Rust for Embedded C Programmers
docs.opentitan.org
docs.opentitan.org
But I'm just going to add my personal observation as a lifelong embedded C developer: I hate the Rust language syntax.
I'm not sure what it is but just trying to grok Rust code grinds my cognitive gears. I'm sure it all serves a purpose and I'm just a cranky old dude that will be left beind someday but, jesus, it just doesn't flow for me.
The rustc_codegen_gcc project aims to solve the backend-availability problem.
I think since it's close to C, my mind wants to read it like C. It's a problem with my brains prefetcher.
Also, finding ` on a non-US keyboard is a pain. Not really related to embedded, but I just had to get it off my chest
(Exception: Rust's syntax for closures is terrible and I don't know anyone who defends it.)
For starters, the reference/borrow checking stuff is opaque. The tick is a lousy visual choice of operator as is 'mut'. The idea that some statements need semicolon terminators while others do not? I don't even want to explore what that's about.
Admittingly Rust solves a harder problem. But I think a huge part of this is also Go language and libraries being very well designed, which Rust could learn a few things from.
Anyway, why did I mention all that? Because Rust makes me feel "well maybe im too stupid to get it" all the time, and now I have realised that a large portion of that is due to ba design choices made by the Rust team and not my own stupidity.
Like you, with Go I was up and running rather quickly. I didn't have to think very hard. It was easy because I didn't have to pick up new concepts, only new syntax.
With Rust I had to learn some new concepts and internalize them, new concepts I generally find much harder than new syntax, but I believe I became a much better programmer (including when writing Go) as a consequence.
Now the journey is majority complete in both languages, and my conclusion isn't that Rust or Go made a pile of bad design choices, rather that the languages made different trade offs that appeal to different people in different circumstances.
Go pushes a lot of expectations of behavior during runtime onto the author while writing (don't share mutable state between threads without appropriate care, always remember to manually free your (not memory) resources, don't deref a null pointer, don't use a returned value if err != nil, etc).
Rust pushes a lot of expectations of knowledge onto the author while writing just to get the project to compile (ownership, lifetimes, sum types, address all the above mentioned Go expectations).
It's been years since I started using both languages, and I've spent months dealing with bugs in Go. I believe a lot of those bugs could have happened in any language, but also a lot wouldn't have made it past rustc.
Which is the winner for specific type of situation? I don't think we can know for a long time, studying such things is very difficult and takes a lot of time.
In the mean time, we gravitate towards our personal preferences, believing them to be superior for $reasons.
1) Really short keywords and basic type names - pub, mut, fn, impl, i8/i16/i32, etc. They're not hard to understand on their own, but in practice they make the language visually choppy.
2) Maybe it's because I learned Kotlin and Typescript shortly before taking on Rust, but "->" feels inconsistent with the rest of the language. It should be a colon.
3) Rust's if statements follow the normal "if <condition> { <result> }" syntax. Yet, for some reason, each branch of a match statement goes "<condition> => <result>." What would have been wrong with "case <condition> { <result> }"? I know it's more characters, but putting a keyword at the beginning of the block would help to visually separate each branch.
4) Rust's closure syntax looks strange (and I've used Ruby before). Maybe that's just me, though.
Rust isn't perfect, but I don't want to discourage other embedded C programmers from giving it an honest shot. The embedded library support isn't really there yet, but the language itself is a huge upgrade over C and C++.
(edit: I, for one, like the 'lifetimes.)
I saw something I didn't understand and wanted to understand better. Not much more to it.
It reads like a diff, and is very effective, I'd say, for any programmer.