Closed dhylands closed 7 years ago
Looks nice overall! One thing I don't like is the overflow behavior. I would prefer the formatting function to return a bool to notifiy the caller that formatting was not possible. I think that would also let us get rid of the custom cases for when the filler is ' ' or not.
This changes the routines to return a bool, true = number formatted ok, false = overflow.
In the case of an overflow, the contents of the buffer may be modified, and won't represent the number passed in.
I also have this in a separate repository so I could run cargo test https://github.com/dhylands/format-rs
If you want, I could link to that, or just leave format.rs in this repo.
lgtm!
Here's a pair of formatting routines.
If you run the example format_into.rs then I get the following output:
There are also some tests. I haven't been able to get the tests to work inside this crate, but they worked in a standalone crate.