930a71460f
The new SizeUnit type takes over the auto scaling logic and could be used on its own too. Switch the internal type of HumanByte from u64 to f64, this results in a slight reduce of usable sizes we can represent (there's no unsigned float type after all) but we support pebibyte now with quite the precision and ebibytes should be also work out ok, and that really should us have covered for a while.. Partially adapted by Dietmar's version, but split up and change so: * there's no None type, for a SizeUnit that does not makes much sense * print the unit for byte too, better consistency and one can still use as_u64() or as_f64() if they do not want/need the unit rendered * left the "From usize/u64" impls intact, just convenient to have and avoids all over the tree changes to adapt to loosing that * move auto-scaling into SizeUnit, good fit there and I could see some re-use potential for non-human-byte users in the future * impl Display for SizeUnit instead of the separate unit_str method, better usability as it can be used directly in format (with zero alloc/copy) and saw no real reason of not having that this way * switch the place where we auto-scale in HumanByte's to the new_X helpers which allows for slightly reduced code usage and simplify implementation where possible * use rounding for the precision limit algorithm. This is a stupid problem as in practices there are cases for requiring every variant: - flooring would be good for limits, better less than to much - ceiling would be good for file sizes, to less can mean ENOSPACE and user getting angry if their working value is messed with - rounding can be good for rendering benchmark, closer to reality and no real impact So going always for rounding is really not the best solution.. Some of those changes where naturally opinionated, if there's a good practical reason we can switch back (or to something completely different). The single thing I kept and am not _that_ happy with is being able to have fractional bytes (1.1 B or even 0.01 B), which just does not makes much sense as most of those values cannot exist at all in reality - I say most as multiple of 1/8 Byte can exists, those are bits.o Note, the precission also changed from fixed 2 to max 3 (trailing zeros stripped), while that can be nice we should see if we get a better precision limiting algorithm, e.g., directly in the printer. Rust sadly does not supports "limit to precision of 3 but avoid trailing zeros" so we'd need to adapt their Grisu based algorithm our own - way to much complexity for this though.. Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com> |
||
---|---|---|
.. | ||
src | ||
Cargo.toml |