bytesize icon indicating copy to clipboard operation
bytesize copied to clipboard

Implement `no_std` support with simplified `to_string`

Open AdnoC opened this issue 2 years ago • 2 comments

My attempt at resolving https://github.com/hyunsik/bytesize/issues/3.

Some things had to change. Firstly, in order to support alignment format specifiers we would have to write to a buffer and then Formatter::pad that. So we do not support alignment in no_std. I can add that if that is a requirement, but I felt that implementing the buffer would be a lot.

Also, the algorithm used to select the correct units had to change. no_std does not have access to complex math like ln. So we just manually check which unit is correct and go from there.

Nothing should be changed when std is enabled. These things are conditionally changed when the std feature is disabled.

If you test with cargo test --no-default-features it will run all the tests that can be run with no_std.

Oh! Also I put aside the parsing element. None of that is enabled when not using the standard library.

AdnoC avatar Aug 23 '23 02:08 AdnoC

I'm sorry for a late review. I'll review asap by this week.

hyunsik avatar Sep 06 '23 00:09 hyunsik

Rebased off of master because there were merge conflicts.

The example showing the use of to_string_as was breaking no-std tests (because there is no String without std), so I had to update the doc comment to only render when std is enabled.

AdnoC avatar Sep 07 '23 15:09 AdnoC