Skip to main content

strate_init/
fmt.rs

1//! Formatting utilities for the init process (no heap allocation).
2
3use crate::log;
4
5/// Format a u32 as decimal digits and write it via `log()`.
6///
7/// Handles up to 10 digits (max 4 294 967 295).  
8/// Zero-padded bytes in the buffer may be read by `from_utf8_unchecked` but are never written to `log` (the slice is trimmed).
9pub fn log_u32(mut value: u32) {
10    let mut buf = [0u8; 10];
11
12    if value == 0 {
13        log("0");
14        return;
15    }
16
17    let mut i = buf.len();
18
19    while value > 0 {
20        i -= 1;
21        buf[i] = b'0' + (value % 10) as u8;
22        value /= 10;
23    }
24
25    let s = unsafe { core::str::from_utf8_unchecked(&buf[i..]) };
26
27    log(s);
28}