Is Rust useful for embedded Linux glue logic?

Hey, sorry for the long title. This isn't going to be a very well thought out post, please bear with me.

I've been tired of writing C for the past few years. It's very hard to get right. I've been noticing that most the platforms and situations I care about writing C in now have somewhat decent Rust support, so I gave it a shot.

I rewrote a small C program that plays tones through Linux beep devices using the C FFI for the OS-level stuff, Tokio, dynamic dispatch, and some neat features of Rust. It came out decent enough, with the code being less confusing and about the same size.

My impressions are overall good, though I don't know much about unsafe Rust yet so I don't really know whether I would be able to safely write unsafe Rust.

The problem is this is only part of the solution: I still have scripts and glue code in languages like shell that run my binaries, usually with painful constraints like using Busybox's limited capabilities and really poor error handling.

So it sounds to me like I need a scripting language of some sort to handle the high level logic? Something like Python doesn't fit well on embedded devices due to size constraints, and embedding a scripting language in my program means I can't pull the logic out in to a library for other program's use.

So my questions are:

  • Could I use Rust for high level glue logic?
  • Is a scripting language a better idea?
  • If so, why have Rust be sandwiched between C and the language?

I suspect I may be greatly underestimating how painful it is to use Rust for high level logic. I'd appreciate some real world examples if anyone has any.

What you're asking is subjective; I don't think you're going to get a better answer here than you'd get by just trying it out and seeing what happens. That being said...

...IMO Rust is significantly less painful to write high level logic in than shell scripts. I would not worry about this.

Here's the first script-like Rust code I could find in the rust compiler repository:

Thanks for the response!

I suspect you're right, and I honestly don't know why I didn't just try it yet. I think I'll devise a somewhat meaningful program, write it in shell, Python, C and Rust and see what works out better.

1 Like