How to use the std crate on embedded platforms


I’ve recently started to look at Rust since it seems a very promising language to me (I come from C/C++ mainly).
I’ve also done lot of embedded development in the past few years and so I looked around on how to use Rust for that too.
Lots of things are already available but I still can’t find an answer to a question I have: what needs to be done in order to be able to use the std crate?
I completely understand that it can’t be used directly since there is no OS available to handle memory allocation, threads and stuff but how could I make this possible?
When doing C/C++, I’m used to have a file with all the standard system calls (_write(), _sbrk(), _fork(), etc) provided with a either a real implementation (redirecting _write() calls to a serial port for instance) or a dummy implementation that just fails if you try to use it.
Is it possible to have this kind of mechanism? I would love to be able to glue Rust’s std library with some kind of basic OS (FreeRTOS for example) to have an experience as natural as possible.


One of the search terms you are looking for is “lang_items” that you can implement, such as the memory allocator and the panic unwinder.

I’m not good at rust embedded, but I’ve learned a thing or two by lurking Phill Opperman rust kernel series.


and japaric’s work is excellent:

Especially the “photon quickstart” may be of interest, that glues rust to the freeRTOS-based runtime, using dark magicks that are currently beyond me:

I haven’t tried things myself (yet)


Thank you very much for the information, I’ll look into it!


Oh, and before I forget!

A lot of things from std, that don’t need allocations, such as the Result and Option types, can be used by selectively useing them from core.

The std “rust preamble” is just a convenience re-export of core and some other useful things


You might also be interested in and


The refactoring of std looks very promising!
The only downside it’s that it will take a still undefined amount of time to be completed so I don’t know if it’s better to wait for it or do something now, knowing that it’s only temporary. It was for a side/hobby project so maybe it’s better to wait and do something else in the meantime.