From 61dfa7d779e26e4cbbb6e6fa7fdc14294224bfba Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Sun, 13 Apr 2025 03:07:17 -0400 Subject: [PATCH] Bump `bytesize` from major version 1 to 2 This upgrades the `bytesize` dependency in `Cargo.toml` from version 1.0.1 (which was usually selecting 1.3.3) to 2.0.1 (which is the latest version). There were some nontrivial API changes from major version 1 to 2. Accordingly, this adapts `Bytes::format_bytes()` to the API change. The old `bytesize::to_string()` function was confusing in its second parameter `si_prefix: bool`, which is why it was removed. But it looks like a value of `false`, as we were passing, actually caused decimal SI units (rather than binary IEC units) to be used. It's not obvious which units `prodash` intended to use `bytesize` to convert to and display in. But this seems to be a minimal change to adapt to the new major version. In spite of the name `si_prefix` for the old parameter, experiments show that setting it to `true` caused values to be converted to and presented in binary IEC units. Although this attempts not to change which actual units are used, it does produce observable differences for some of them, in how they are presented. In particular, a decimal SI kilobyte is least ambiguously abbreviated "kB" (because "k" is an SI unit symbol prefix for "kilo" in its meaning of 1000), but it was previously written as "KB". It is now expected to be writen as "kB". Tests catch this distinction, and are updated here accordingly to assert that the generally preferable "kB" symbol for decimal SI kilobyte is used. See also: https://github.com/GitoxideLabs/gitoxide/issues/1947#issuecomment-2795974907 --- Cargo.toml | 2 +- src/unit/bytes.rs | 2 +- tests/unit/mod.rs | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5e2d063..cf1d2b9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -84,7 +84,7 @@ signal-hook = { version = "0.3.9", optional = true, default-features = false } is-terminal = { version = "0.4.9", optional = true } # units -bytesize = { version = "1.0.1", optional = true } +bytesize = { version = "2.0.1", optional = true } human_format = { version = "1.0.3", optional = true } [package.metadata.docs.rs] diff --git a/src/unit/bytes.rs b/src/unit/bytes.rs index a79f971..71371c4 100644 --- a/src/unit/bytes.rs +++ b/src/unit/bytes.rs @@ -8,7 +8,7 @@ pub struct Bytes; impl Bytes { fn format_bytes(w: &mut dyn fmt::Write, value: Step) -> fmt::Result { - let string = bytesize::to_string(value as u64, false); + let string = bytesize::ByteSize(value as u64).display().si().to_string(); for token in string.split(' ') { w.write_str(token)?; } diff --git a/tests/unit/mod.rs b/tests/unit/mod.rs index 0032f3d..d22903f 100644 --- a/tests/unit/mod.rs +++ b/tests/unit/mod.rs @@ -60,12 +60,12 @@ mod dynamic { None ) ), - "1.0KB/10.0GB [0%]" + "1.0kB/10.0GB [0%]" ); } #[test] fn just_value() { - assert_eq!(format!("{}", unit::dynamic(Bytes).display(5540, None, None)), "5.5KB"); + assert_eq!(format!("{}", unit::dynamic(Bytes).display(5540, None, None)), "5.5kB"); } } }