Skip to content

Commit c8ffeb4

Browse files
committed
chore: remove useless B constant
1 parent 1e4072b commit c8ffeb4

File tree

3 files changed

+24
-34
lines changed

3 files changed

+24
-34
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@
1111
- Reject parsing non-unit characters after whitespace.
1212
- Remove `ByteSize::to_string_as()` method.
1313
- Remove top-level `to_string()` method.
14+
- Remove top-level `B` constant.

src/lib.rs

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -33,28 +33,26 @@ mod serde;
3333
use std::fmt::{self, Debug, Display, Formatter};
3434
use std::ops::{Add, AddAssign, Mul, MulAssign, Sub, SubAssign};
3535

36-
/// byte size for 1 byte
37-
pub const B: u64 = 1;
38-
/// bytes size for 1 kilobyte
36+
/// Number of bytes in 1 kilobyte.
3937
pub const KB: u64 = 1_000;
40-
/// bytes size for 1 megabyte
38+
/// Number of bytes in 1 megabyte.
4139
pub const MB: u64 = 1_000_000;
42-
/// bytes size for 1 gigabyte
40+
/// Number of bytes in 1 gigabyte.
4341
pub const GB: u64 = 1_000_000_000;
44-
/// bytes size for 1 terabyte
42+
/// Number of bytes in 1 terabyte.
4543
pub const TB: u64 = 1_000_000_000_000;
46-
/// bytes size for 1 petabyte
44+
/// Number of bytes in 1 petabyte.
4745
pub const PB: u64 = 1_000_000_000_000_000;
4846

49-
/// bytes size for 1 kibibyte
47+
/// Number of bytes in 1 kibibyte.
5048
pub const KIB: u64 = 1_024;
51-
/// bytes size for 1 mebibyte
49+
/// Number of bytes in 1 mebibyte.
5250
pub const MIB: u64 = 1_048_576;
53-
/// bytes size for 1 gibibyte
51+
/// Number of bytes in 1 gibibyte.
5452
pub const GIB: u64 = 1_073_741_824;
55-
/// bytes size for 1 tebibyte
53+
/// Number of bytes in 1 tebibyte.
5654
pub const TIB: u64 = 1_099_511_627_776;
57-
/// bytes size for 1 pebibyte
55+
/// Number of bytes in 1 pebibyte.
5856
pub const PIB: u64 = 1_125_899_906_842_624;
5957

6058
/// IEC (binary) units.
@@ -416,21 +414,12 @@ mod tests {
416414
let mut x = ByteSize::mb(1);
417415

418416
assert_eq!((x + MB as u64).as_u64(), 2_000_000);
419-
420417
assert_eq!((x + MB as u32).as_u64(), 2_000_000);
421-
422418
assert_eq!((x + KB as u16).as_u64(), 1_001_000);
423-
424-
assert_eq!((x + B as u8).as_u64(), 1_000_001);
425-
426419
assert_eq!((x - MB as u64).as_u64(), 0);
427-
428420
assert_eq!((x - MB as u32).as_u64(), 0);
429-
430421
assert_eq!((x - KB as u32).as_u64(), 999_000);
431422

432-
assert_eq!((x - B as u32).as_u64(), 999_999);
433-
434423
x += MB as u64;
435424
x += MB as u32;
436425
x += 10u16;

src/parse.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,19 @@ enum Unit {
7070
impl Unit {
7171
fn factor(&self) -> u64 {
7272
match self {
73-
Self::Byte => super::B,
74-
// power of tens
75-
Self::KiloByte => super::KB,
76-
Self::MegaByte => super::MB,
77-
Self::GigaByte => super::GB,
78-
Self::TeraByte => super::TB,
79-
Self::PetaByte => super::PB,
80-
// power of twos
81-
Self::KibiByte => super::KIB,
82-
Self::MebiByte => super::MIB,
83-
Self::GibiByte => super::GIB,
84-
Self::TebiByte => super::TIB,
85-
Self::PebiByte => super::PIB,
73+
Self::Byte => 1,
74+
// decimal units
75+
Self::KiloByte => crate::KB,
76+
Self::MegaByte => crate::MB,
77+
Self::GigaByte => crate::GB,
78+
Self::TeraByte => crate::TB,
79+
Self::PetaByte => crate::PB,
80+
// binary units
81+
Self::KibiByte => crate::KIB,
82+
Self::MebiByte => crate::MIB,
83+
Self::GibiByte => crate::GIB,
84+
Self::TebiByte => crate::TIB,
85+
Self::PebiByte => crate::PIB,
8686
}
8787
}
8888
}

0 commit comments

Comments
 (0)