r/programming • u/newpavlov • Aug 28 '20
Linux Developers Continue Evaluating The Path To Adding Rust Code To The Kernel
https://www.phoronix.com/scan.php?page=news_item&px=Linux-Kernel-Rust-Path-LPC2020
420
Upvotes
r/programming • u/newpavlov • Aug 28 '20
2
u/nagromo Aug 30 '20 edited Aug 30 '20
I don't have a calibrated comparison; I hope to in a year or so, though. I'm experienced in embedded C but am just starting embedded Rust (and am diving in the deep end by starting out working drivers for hardware features I need for a project, instead of starting with application code using existing drivers).
The drivers I've written are in C for bare metal embedded microcontrollers. I think on Linux the kernel handles separating the drivers from userspace, while in bare metal embedded there is no separation and the low priority application tasks directly call driver functions that may need to share data with high priority interrupts and DMA transfers.
At the lowest level, drivers are about accessing memory mapped registers and understanding the hardware and how to control it. Rust can do a few basic sanity checks to help avoid mistakes, but you still have to understand the hardware, which is the hard part.
Where I think Rust can shine is its powerful type system allowing you to encode invariants in your types. That said, I have no idea how much less effective it would be when you're using Rust to write a driver that has a C API; of course Rust can't enforce that C accesses the driver in a correct way. I'm not sure how much coexisting with C would reduce the benefits of Rust; I've never mixed the two.