https://github.com/cbebe/os-rust
My attempts to rewrite my Operating Systems course assignments (written in C) in Rust
https://github.com/cbebe/os-rust
Last synced: over 1 year ago
JSON representation
My attempts to rewrite my Operating Systems course assignments (written in C) in Rust
- Host: GitHub
- URL: https://github.com/cbebe/os-rust
- Owner: cbebe
- Created: 2021-12-05T07:59:59.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-07-01T23:33:28.000Z (about 4 years ago)
- Last Synced: 2025-01-24T10:08:23.512Z (over 1 year ago)
- Language: Rust
- Homepage:
- Size: 39.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# OS Concepts Assignments in Rust
My attempts to rewrite my Operating Systems course assignments (written in C)
in Rust
## Why?
I've tried countless of times to get into Rust because of all the hype
surrounding it, but always found it too hard :P
I also had no projects that called for its use and always opted for
JavaScript/TypeScript because of its familiarity and it was always good enough.
This made me less motivated to learn Rust and never touched it again for a long
time.
Then comes my Operating Systems course, which required C/C++ for assignments.
It was almost impossible at first with a lot of C and systems programming
pitfalls but I eventually got the hang of it by the third assignment. These are
the kinds of things that Rust is supposed to fix, so it was the perfect
applications for learning Rust.
## Shell - Thoughts
Rust is hard :'(
### Cons
- I have to handle every single error that can happen, which makes error
handling messy. I will probably have to try creating my own custom `Result`
types and stop spamming `Result<(), Box>` everywhere.
- Dealing with string types was also difficult. While C only has `char *`
(sometimes with `const`), I have to use `str`, `String`, `Vec`, and call
whatever conversions between those types to get it to compile.
### Pros
- Everything (almost) went smoothly when it did compile. Aside from logical
errors that came up because of differences in string methods and the deadlock
happening with the signal handler, there were no other runtime errors. This
might be because I already wrote this program, though, and I might already
have smoothed out any problems I would have encountered before.
- Still better error handling than C. The `?` operator kind of reminds me of
the `await` construct in Javascript, passing the error handling to the
caller. I've leveraged that a lot in this application.
## Producer-Consumer - Thoughts
Actually pretty surprised by this one
### Cons
- Using shared memory in the C way is pretty difficult to do in Rust, making me
use `unsafe` to access that one variable. Maybe if I wrote this in more
idiomatic Rust, it wouldn't be this bad, but I am writing this months after I
finished this part.
### Pros
- I was expecting this to be a bit slower than my C code, but to my surprise,
it actually matched the performance of my original code.