#[path="support/small_bytes.rs"] mod small_bytes; fn main() { use small_bytes::SmallBytes; // checked inline [u8; N] + length helper struct Person { name: SmallBytes<16>, age: i32 } impl std::fmt::Display for Person { fn fmt(&self, out: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let name = std::str::from_utf8(self.name.as_bytes()).map_err(|_| std::fmt::Error)?; write!(out, "{} ({})", name, self.age) } } let mut people: Vec = Vec::new(); people.push(Person { name: SmallBytes::new(b"ada"), age: 36 }); people.push(Person { name: SmallBytes::new(b"grace"), age: 45 }); let mut p = Person { name: SmallBytes::new(b""), age: 20 }; p.name.append(b"linus"); people.push(p); println!("[{}]", people.iter().map(ToString::to_string).collect::>().join(", ")); }