rust-impl-no-std
This skill contains shell command directives (!`command`) that may execute system commands. Review carefully before installing.
rust-impl-no-std
The no_std Rust skill: how to opt out of the standard library with #![no_std], work against core only, pull in alloc when a heap is available, register a #[panic_handler] and optional #[global_allocator], and design a hybrid library that builds on both std and no_std consumers via a default = ["std"] feature.
Cross-references: [[rust-core-stdlib-overview]] (what std contains that core does not), [[rust-impl-cargo-project]] (features, profiles, panic = "abort"), [[rust-syntax-unsafe]] (#[global_allocator] involves the unsafe GlobalAlloc trait), [[rust-impl-cross-compile]] (thumbv7em-none-eabihf and other bare-metal targets).
When to use this skill
- User adds
#![no_std]tolib.rs/main.rsand the compiler starts complaining about missing types. - User targets an embedded board (Cortex-M, RISC-V MCU) and asks how to structure the crate.
- User wants
Vec/Box/Stringin a no_std crate and is unsure whetherallocis allowed. - User writes their first
#[panic_handler]or hits the "duplicate panic handler" link error. - User wants to plug in a custom allocator via
#[global_allocator]. - User has a library that some users will consume from std applications and others from no_std firmware, and asks how to support both.
- User asks why
std::format!doesn't compile in their crate. - User asks why
HashMapcannot be imported fromalloc.