A GPIO driver in Rust
A GPIO driver in Rust
Posted Jul 19, 2021 17:08 UTC (Mon) by rvolgers (guest, #63218)Parent article: A GPIO driver in Rust
I notice I get annoyed at the lack of explicit types on variables and things like ".into()" (which likewise doesn't offer much clue as to typing, just that a conversion is happening). In C, it's relatively important to be aware of types. On one hand due to various traps related to UB and integer arithmetic, and on the other hand because there are no guard rails on most APIs. Rust really encourages you to embed restrictions in the API, so that the use site can be a lot more terse.
Also with "C brain" engaged, some of the nested control flow like in `Chip::get_direction` seems weird. But objectively, I think the Rust version is quicker to read.
I do notice that the indentation is 4 spaces in the Rust version. Pretty sure that's because they're using Rust defaults for formatting and also pretty sure there has been a lot of discussion about this already and I really don't want to start that again. But just mentioning it since it does make nesting look a little worse in the C case.
Posted Jul 19, 2021 22:14 UTC (Mon)
by roc (subscriber, #30627)
[Link]
But I can see why the kernel might not want to assume code readers have such capabilities available.
A GPIO driver in Rust
