by ekidd · 9y ago · 0 comments
Rust is a surprisingly nice language on bare metal.
If you use '#![no_std]' in Rust, it disables the standard library and substitutes the 'core' library. This has no 'malloc' (unless you supply one, which is easy) and no OS-level features. But you still get iterators, slices, traits, "scoped" closures and generic types. You get a lot of abstraction with basically zero overhead. And don't forget that embedded systems have lot of state machines, which are nice to implement using Rust's "tagged union" support and exhaustive 'match' statement.
Here's an example of a Rust I/O port wrapper (https://github.com/emk/toyos-rs/tree/master/crates/cpuio) and an interrupt controller interface (https://github.com/emk/toyos-rs/tree/master/crates/pic8259_s...). These APIs are reasonably pleasant for something so close to the metal.
Rust would be a very agreeable programming language on an AVR system, IMO. And not necessarily because of pointer safety, either.
I tear my hair out every time I have to wrestle with C for the simplest things, though, whereas Rust is a joy to write.