Chapter 6. Beyond Standard Rust

The Rust toolchain includes support for a much wider variety of environments than just pure Rust application code, running in userspace:

  • It supports cross-compilation, where the system running the toolchain (the host) is not the same as the system that the compiled code will run on (the target), which makes it easy to target embedded systems.

  • It supports linking with code compiled from languages other than Rust, via built-in FFI capabilities.

  • It supports configurations without the full standard library std, allowing systems that do not have a full operating system (e.g., no filesystem, no networking) to be targeted.

  • It even supports configurations that do not support heap allocation but only have a stack (by omitting use of the standard alloc library).

These nonstandard Rust environments can be harder to work in and may be less safe—they can even be unsafe—but they give more options for getting the job done.

This chapter of the book discusses just a few of the basics for working in these environments. Beyond these basics, you’ll need to consult more environment-specific documentation (such as the Rustonomicon).

Item 33: Consider making library code no_std compatible

Rust comes with a standard library called std, which includes code for a wide variety of common tasks, from standard data structures to networking, from multithreading support to file I/O. For convenience, several of the items from std are automatically imported into your ...

Get Effective Rust now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.