#[path="support/small_bytes.rs"] mod small_bytes; use small_bytes::SmallBytes; 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) } } fn main() { let people = [Person {name:SmallBytes::new(b"ada"),age:36},Person {name:SmallBytes::new(b"grace"),age:45},Person {name:SmallBytes::new(b"linus"),age:20}]; use std::io::{self, Write}; let who: &[u8] = if people.len() > 3 { b"a crowd" } else { people[1].name.as_bytes() }; let mut out = io::stdout().lock(); out.write_all(who).unwrap(); out.write_all(b"\n").unwrap(); }