dtolnay/itoa

Expose API to write to user-provided buffer

Closed this issue · 2 comments

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).

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.

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.