Function display_utils::collect_str_mut[][src]

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.

Can be used in combination with all of the functions in this crate that returns Display.

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",
);