dtolnay / itoa

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

Expose API to write to user-provided buffer #33

Closed Jules-Bertholet closed 2 years ago

Jules-Bertholet commented 2 years ago

I need to pass the string that itoa returns to C, which means I need to add a null byte at the end. But there's no way to do that with the &str that format returns, short of copying the string's contents to an entirely new buffer.

If itoa exposed a method that accepted a pointer or reference to a user-created MaybeUninit buffer of the right size, I would be able to do this easily (just set the index one past the number of bytes that were written to 0).

dtolnay commented 2 years ago

I would prefer not to build this into this crate. You can copy the strings to your own buffer or you can fork the crate.

clarfonthey commented 2 years ago

Is there a particular reason why you'd rather not include this? It seems unnecessary to fork a crate for such a small addition, and copying the string seems suboptimal considering how this crate was designed with performance in mind.