A `no_std` program uses `#![no_std]` at the top of its crate to exclude Rust’s standard library. This is useful for a kernel or embedded program that cannot rely on an operating system to provide dynamic memory allocation. Standard-library types such as `Vec<T>` are then unavailable. section 11.2.3 section 11.7
Removing the standard library also means supplying functionality an ordinary Rust program receives automatically. In particular, the program needs a panic handler. A minimal kernel can abort on panic; an infinite loop is another option, but it keeps a CPU core busy until shutdown. section 11.2.4
A kernel that writes to the screen
Place `#![no_std]` and `#![no_main]` above a panic handler and an `_start` function. In this small kernel, `_start` writes a byte to a framebuffer address and then loops forever: there is no operating system to return to. section 11.2.3
Listing 11.4 Creating an OS kernel that paints a block of color
1 #![no_std] #1
2 #![no_main] #1
3 #![feature(core_intrinsics)] #2
4
5 use core::intrinsics; #2
6 use core::panic::PanicInfo; #3
7
8 #[panic_handler]
9 #[no_mangle]
10 pub fn panic(_info: &PanicInfo) -> ! {
11 intrinsics::abort(); #4
12 }
13
14 #[no_mangle]
15 pub extern "C" fn _start() -> ! {
16 let framebuffer = 0xb8000 as *mut u8;
17
18 unsafe {
19 framebuffer
20 .offset(1) #5
21 .write_volatile(0x30); #6
22 }
23
24 loop {}
25 }
The complete listing puts the crate attributes, panic handler, entry point, and framebuffer write together. section 11.2.3
As the kernel grows, other functionality normally supplied through libraries may also need an explicit implementation. The minimal exception-handling personality routine is one example. section 11.4.1

