dtolnay / itoa

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

Return io::Result<usize> instead of io::Result<()> #6

Closed nox closed 7 years ago

nox commented 7 years ago

There is no way to know how many bytes were written in the result, which is a problem when using write with a stack-allocated array. Returning io::Result<usize> would allow this:

let mut buf = [b'\0'; 20];
let len = itoa::write(&mut buf, value)?;
let result = &buf[0..len];