I'm trying to format an u64
to a &str
, but without dynamically allocating any memory on heap. I want to manually declare a space on stack (e.g., let mut buffer = [0u8; 20]
and print the u64
to buffer
and get a &str
from it with some unsafe.
I tryied write!(&mut buffer[..], "{}", i)
, but it returns a Result<()>
and I couldn't get the length of the formatted string so as to unsafely convert it to &str.
I'm currently straightly coping the implementation of Display for u64
from std library, is there a better way of doing so?