Hacker News new | ask | show | jobs
by exposition 964 days ago
Has anybody else used Rust for embedded?

Would be interested to hear your experience.

So far, I’ve seen mixed reviews. Some say that you can end up using unsafe a lot and so it’s better to stick with C or even use Zig.

Wondered if there was any merit to this.

1 comments

> Some say that you can end up using unsafe a lot and so it’s better to stick with C or even use Zig

Using unsafe in Rust isn't inherently bad. If you're doing embedded work, using unsafe is mandatory once you get to the level of interacting with the hardware.

That doesn't mean the code is literally unsafe, just that the interactions are happening in a way that the compiler can't guarantee. That's completely expected when you're poking at hardware registers.

You still get most of the benefits of Rust, the language. I've had good success with it.

Yep I get that- it's just that using unsafe reduces the benefits you get from Rust's model.

And so I was wondering whether using it is still worth it.

Obviously, it probably still has many benefits over C but something like Zig might be simpler and better suited.

> it's just that using unsafe reduces the benefits you get from Rust's model.

No, you still get the benefits where it matters.

The "unsafe" is basically marking a boundary where you're doing things outside of what the compiler can verify. If you're poking at hardware registers, that's expected and normal.

Putting "unsafe" in a program at the hardware boundary doesn't reduce the benefits of Rust elsewhere in the program.