How to Write Rust Code Without the Standard Library
Add #![no_std] to the top of your main.rs file to disable the standard library. This forces the compiler to use only the core library, which is essential for embedded systems or bare-metal programming.
#![no_std]
#![no_main]
use core::panic::PanicInfo;
#[panic_handler]
fn panic(_info: &PanicInfo) -> ! {
loop {}
}
#[no_mangle]
pub extern "C" fn main() -> i32 {
// Your code here
0
}
Note: You must also add #![no_main] and define a custom entry point if you are targeting bare-metal environments without an OS.