The Rust apologists replying to this comment are conflating mere understanding of the above chain with the reality of needing to type this slog every time you need to set a pin. When you’re just making a garage door opener in your home electronics lab and a C API offers setBit(&gpioCtx, bitPosition, 1); as an alternative to the above abomination, we all know where developers will be happier and more productive.
You can almost certainly do the same in Rust in an unsafe block.
You will be happier and more productive unless you get bitten by the lack of locking, reference counting and mandatory initialisation. Which is actually quite likely.
Compiled with -Wall is fine and infinitely more readable that the Rust puke above, but you probably won’t need the lock or the warnings in your typical embedded project. The main issue with Rust appears to be that it invites masturbators that invent problem scenarios in their head and then overengineer every std lib API and crate available for consumption. Setting a bit on a dev board should simple. It should not be a chained mess full of operator soup.
But this is never done, because the language attracts people who overengineer. The original commenter was following a beginner’s tutorial in Embedded Rust. They didn’t just unluckily stumble upon something esoteric with too many layers of safety for the functionality they were aiming to achieve. This is how people in the Rust Foundation actually use their language, and it’s how they teach people to use it.
POSIX threads are far more battle-proven than any threading API in Rust. All of the underlying multi-threading on the system you made your comment from is using pthreads. It works fine in reality, despite all the pearl clutching.
>Rust makes it so that you can't forget.
And the tradeoff is an unreadable, puke-inducing one-liner. You can do a (readable) scoped lock with a macro in C (GCC defines the __attribute__ cleanup) or RAII-style with destructors in C++.
The context of this exact discussion is the defense of the ugly Rust code above by Rust aficionados who see nothing wrong with it. That code came from the Embedded Rust working group in their learning material for Rust beginners.
I'm not taking anything out of context. That code is hideous. It's terse. It uses controls and defenses that aren't needed for most embedded applications. It turned a beginner away from the language. When I provided much simpler C code as an alternative, Rust aficionados started to cry about unneeded mutexes, unneeded ref counting, the inability of programmers to remember to call free or mutex_unlock, etc. etc.
Your response is an unrelated rant. Here's your claim:
> But [writing it more simply] is never done
You're not saying anything interesting, you're just making grandiose false claims to start a flame war. Approach it from a good-faith perspective, please.
>oh but you could just use a macro!
Or I could just use C and be productive, thanks.