> Where doesn't Rust 'compete' with C, and where is C the better choice in a kernel?
My opinion as someone who writes C for embedded devices and has started to play with rust:
C is better than Rust primarily when the C code already exists and the Rust code doesn’t.
Rewriting the kernel will probably have little impact in terms of performance for the user, the main benefits would be for developers, because Rust can be more expressive (less boilerplate and simpler ways to do some things), and it should have less bugs, since it’s performing more complex checks than C code would.
For me as an individual, I’d prefer to be writing Rust, I find it much more ergonomic (for my workflow at least). The main drawback I have is that no one else in my team really knows Rust (although that’s slowly changing).
I'm wondering more about accessing hardware primitives - if you spend a dozen lines marshalling unsafe code around and ultimately writing the equivalent C code in Rust, and slightly slower (perhaps the compiler optimizes anyway?), is it worth the effort?
> if you spend a dozen lines marshalling unsafe code around and ultimately writing the equivalent C code in Rust, and slightly slower (perhaps the compiler optimizes anyway?), is it worth the effort?
The thing is, that's not generally where most of the bugs and development blockers lie here. When embedded development gets stuck, is generally because:
a) A part of the hardware doesn't work like you think it works.
b) Two or more independent parts of code (think ISRs) are conflicting in some non trivial way.
Having well structured HALs helps with (a), while memory safety can prevent some errors on (b).
One of the nice things I've seen with Rust is how high quality the HALs look, even if some of the tooling looks a little shaky for my taste. Of course part of that is that manufacturer provided HALs are generally quite bad...
Also having lots of people share the same unsafe blocks is the best way to keep the bugs away, and sharing libraries with cargo beats the real way C code gets shared in embedded development (mostly through copy/paste from StackOverflow...).
My opinion as someone who writes C for embedded devices and has started to play with rust:
C is better than Rust primarily when the C code already exists and the Rust code doesn’t.
Rewriting the kernel will probably have little impact in terms of performance for the user, the main benefits would be for developers, because Rust can be more expressive (less boilerplate and simpler ways to do some things), and it should have less bugs, since it’s performing more complex checks than C code would.
For me as an individual, I’d prefer to be writing Rust, I find it much more ergonomic (for my workflow at least). The main drawback I have is that no one else in my team really knows Rust (although that’s slowly changing).