[−][src]Function display_utils::collect_str
pub fn collect_str(buf: &mut [u8], object: impl Display) -> Result<&str, &str>
Write a Display object into a fixed-size buffer and returns the resulting &str.
Returns Ok if the object fully fits into the given buffer, and Err with the truncated string otherwise.
let mut buf = [0; 20]; assert_eq!( collect_str(&mut buf, format_args!("I have {} apples", 12)), Ok("I have 12 apples"), ); assert_eq!( collect_str(&mut buf, format_args!("I have {} apples", 615233821)), Err("I have 615233821 app"), );