What Is no_std in Rust and When Do You Need It?

The no_std attribute disables the Rust standard library for embedded targets, requiring manual implementation of panic handlers and memory allocation.

The #![no_std] attribute disables the standard library, forcing your crate to rely only on the core library for basic functionality. Use it when building for embedded systems, kernels, or other environments where a full operating system runtime is unavailable.

#![no_std]
#![no_main]

use core::panic::PanicInfo;

#[panic_handler]
fn panic(_info: &PanicInfo) -> ! {
    loop {}
}

You must also provide a panic_handler and, if needed, an alloc_error_handler since std is not present to handle these automatically.