Skip to content

Enhancement: Add a formatting method to detect truncation #1

@tttwang23

Description

@tttwang23

/// Format using a stack buffer. Result in an error if there is truncation.
/// A reference to str is returned in Result.
pub fn fmt_stack<'a>(buffer: &'a mut [u8], args: fmt::Arguments) -> Result<&'a str, fmt::Error> {
let mut w = stackfmt::WriteTo::new(buffer);
fmt::write(&mut w, args)?;
if w.overflow {
Err(fmt::Error)
}
else {
Ok(w.as_str())
}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions