by ziml77 · 3y ago · 0 comments
const INDENTS: [u8; 256] = [b' '; 256];
// ...
IndentStyle::Spaces(n) => unsafe { std::str::from_utf8_unchecked(&INDENTS[0..n as usize]) },
But I would consider having INDENTS be a &str to get the cheap slicing without needing unsafe. Since putting in a string literal of 256 spaces is nasty I would use the const_format crate to generate the constant: const INDENTS: &str = str_repeat!(" ", 256);