Hacker News new | past | comments | ask | show | jobs | submit login

You can use every rust API in that style, even if it wasn't written like that. See the sibling comment here: https://news.ycombinator.com/item?id=30472226



If you think what we're talking about amounts to having a . or not then you have no idea what we're talking about.

Rust's stdlib assumes not only that there is malloc behind the scenes, but that it is ok to panic. Rust itself, including its stdlib, lacks a stable ABI. It also assumes that lots of little allocations and deallocations with a single owner is a valid memory pattern, and that writing directly to specific memory locations is something you never want to do. These are all wrong assumptions for someone writing baremetal. Look up abi_stable and no_std.


Obviously for embedded use cases you’d not want to use std. it’s why we have core. If you want a stable ABI, you can also easily offer a repr(C) interface. I don’t know what to tell you, plenty of people use Rust successfully for embedded programming.


Of course they do, I never claimed otherwise. People also successfully use C++.

If you're learning, however, you know have to understand why you can't use generics (monomorphisation means you're not getting a stable ABI), why you shouldn't use native tagged unions and instead should write your own with unsafe (for total control of how the tag is handled), why you can't use the standard library, why you need to tag most things with repr(C), why the standard ownership patterns the borrow checker beat into you are in the way when writing your own allocator (with plenty of unsafe). Do you see my point?

Both Rust and C++, when writing baremetal, ask you to ignore how to write idiomatic code in their respective languages. This is fine for experienced devs, who will make good use of the additional features for abstraction, but not for newbies IMO.

C and Zig, on the other hand, do not have this problem, as idiomatic C barely uses its standard library (which is garbage anyway) and idiomatic Zig is designed to work baremetal, including the standard library. I certainly don't recommend using C for new developments in most cases, but for learning, well, you need to learn it anyway, even if you're using Rust baremetal. It's effectively what you're writing, albeit with lots of repr and unsafe strewn around.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: