Rust’s core crate supplies fundamental types, traits, and APIs without requiring an operating system or heap. In bare-metal firmware, a no_std build omits std and uses core as its baseline, alongside a target-appropriate startup or runtime crate. section 1.3 section 7.1.2
Core includes primitive types, references, slices and arrays; traits such as Iterator, Debug and Clone; Option and Result; and Cell and RefCell. Atomic types are available where the target supports them. section 1.3.1 section 7.1.2
Unlike std, core does not provide files, sockets, threads or a default heap. For firmware that does not need dynamic allocation, prefer stack or static storage and fixed-capacity data structures. section 1.3.1 section 7.1.2
#![no_std]
fn my_function() {
// Will not compile in pure `no_std` (no allocator available):
// let v: Vec<u8> = Vec::new();
// Use fixed-capacity data instead:
let mut buf: [u8; 32] = [0; 32];
let mut len = 0;
if len < buf.len() { buf[len] = 0xAB; len += 1; }
}
A fixed-size byte array replaces a heap-allocating Vec in a no_std function. The separate length tracks how much of the buffer is used. section 1.3.1
When heap-backed types such as Vec, String or Box are genuinely needed, a no_std program can add alloc. Declare extern crate alloc at the crate root and provide a global allocator; without an allocator, the program will not link. Allocation can also fail on a memory-constrained microcontroller. section 7.1.2
