Expand description
Prevents automatically linking the standard library.
Written as an inner attribute at the top of the crate root, the no_std attribute stops
the compiler from linking std into the crate, and only links core.
The attribute also swaps which prelude gets inserted, with the core prelude replacing
the std prelude. Items like Option, Result, and the primitive types remain
available from core without any imports needed:
Anything that requires heap memory allocations is not part of core. Linking the alloc
crate explicitly can be used to include these types:
A no_std binary also removes the startup routine and default panic handler std
normally provides. It must define its own #[panic_handler], and typically its own
entry point by additionally using #![no_main]:
#![no_std]
#![no_main]
use core::panic::PanicInfo;
#[panic_handler]
fn on_panic(_info: &PanicInfo) -> ! {
loop {}
}For more information, see the Reference on the no_std attribute.