dtolnay / itoa

Fast function for printing integer primitives to a decimal string
Apache License 2.0
306 stars 37 forks source link

Support for prefix/postfixed buffer #28

Closed adnan449 closed 3 years ago

adnan449 commented 3 years ago

Most of the times, the buffer has prefix/postfix strings and you need to append/prepend a number to it. An API comparable to this would be ideal:

fn demo_itoa_fmt() -> fmt::Result {
    // Write to a string.
    let mut s = String::from("Result is: ");
    itoa::fmt_append(&mut s, 128u64)?;
    println!("{}", s); 

    Ok(())
}
dtolnay commented 3 years ago

This is already supported and does not require a new API.

fn main() {
    let mut s = String::from("Result is: ");
    s.push_str(itoa::Buffer::new().format(128u64));
    println!("{}", s); 
}