[][src]Function display_utils::collect_str_mut

pub fn collect_str_mut(
    buf: &mut [u8],
    object: impl Display
) -> Result<&mut str, &mut str>

Write a Display object into a fixed-size buffer and returns the resulting &mut 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)).unwrap(),
    "I have 12 apples",
);

assert_eq!(
    collect_str(&mut buf, format_args!("I have {} apples", 615233821)).unwrap_err(),
    "I have 615233821 app",
);