Formatting Is Unreasonably Expensive for Embedded Rust
jamesmunns.com
jamesmunns.com
Solving this without pushing too much complexity onto the developer (1) is going to be a fascinating challenge.
(1) What does "too much complexity" look like? The C++ standard library has template arguments for the memory allocation logic. When it's needed, it's very much needed; when it isn't, the existence of that argument was long a tax on comprehending compile-time template errors until tooling caught up with being able to intelligently hide those arguments when they're likely to be noise.
With Go there's TinyGo which solves this problem (note, I haven't used it so can't speak to how well). I wonder if something similar for Rust is possible, a compiler targeting embedded systems?
So Rust can naturally also play there.
Then there is the embedded community stuck on Assembly and C89 mentality, where even C++ doesn't manage to get a foot on, let alone Rust.
fn inner_main() -> Result<(), ()>
should be: fn inner_main() -> Result<!, ()>
since it shouldn't return except in the case of an error. It's important to make the compiler aware of such semantics, so that it can better optimise the program.> All examples provided below are sourced from this repository.
In that sentence "this repository" is a link however it has no affordance [1] until you hover a mouse over it.
1. https://uxplanet.org/ux-design-glossary-how-to-use-affordanc...
It seems the problem for the author is that either they get string based output with a big printf, or no printf at all, and replacing printf is hard. In c replacing printf with a tiny limited implementation is easy and common.
Embedded compilers quite often will include two implementations of printf/sprintf - 'minimal' and 'full' (like solution 2 in the post). Usually the 'minimal' implementation doesn't have floating point support and suchlike so is sufficient for normal debugging output.
The sort of libraries that you depend on in embedded development don't implicitly print. There's none of the 'implicit panics will cause an extra 15k of space'.
It's a normal symbol fed to the linker rather anything special and compiler managed so it can be overriden if necessary.
That's not to say the post isn't enlightening. It is, the cost is unexpectedly high in space. That's not to say that the goals of making unwrap and panic more space efficient are good ones as well. I don't think they're a concern I personally have with rust in an embedded system though.