2
2
//!
3
3
//! Features:
4
4
//!
5
- //! - Pre-defined constants for various size units (e.g., B, Kb, Kib, Mb, Mib, Gb, Gib, ... PB ).
5
+ //! - Pre-defined constants for various size units (e.g., B, Kb, Kib, Mb, Mib, Gb, Gib, ... EB ).
6
6
//! - `ByteSize` type which presents size units convertible to different size units.
7
7
//! - Arithmetic operations for `ByteSize`.
8
8
//! - `FromStr` impl for `ByteSize`, allowing for parsing string size representations like "1.5KiB"
@@ -68,6 +68,8 @@ pub const GB: u64 = 1_000_000_000;
68
68
pub const TB : u64 = 1_000_000_000_000 ;
69
69
/// Number of bytes in 1 petabyte.
70
70
pub const PB : u64 = 1_000_000_000_000_000 ;
71
+ /// Number of bytes in 1 exabyte.
72
+ pub const EB : u64 = 1_000_000_000_000_000_000 ;
71
73
72
74
/// Number of bytes in 1 kibibyte.
73
75
pub const KIB : u64 = 1_024 ;
@@ -79,6 +81,8 @@ pub const GIB: u64 = 1_073_741_824;
79
81
pub const TIB : u64 = 1_099_511_627_776 ;
80
82
/// Number of bytes in 1 pebibyte.
81
83
pub const PIB : u64 = 1_125_899_906_842_624 ;
84
+ /// Number of bytes in 1 exbibyte.
85
+ pub const EIB : u64 = 1_152_921_504_606_846_976 ;
82
86
83
87
/// IEC (binary) units.
84
88
///
@@ -146,6 +150,16 @@ pub fn pib<V: Into<u64>>(size: V) -> u64 {
146
150
size. into ( ) * PIB
147
151
}
148
152
153
+ /// Converts a quantity of exabytes to bytes.
154
+ pub fn eb < V : Into < u64 > > ( size : V ) -> u64 {
155
+ size. into ( ) * EB
156
+ }
157
+
158
+ /// Converts a quantity of exbibytes to bytes.
159
+ pub fn eib < V : Into < u64 > > ( size : V ) -> u64 {
160
+ size. into ( ) * EIB
161
+ }
162
+
149
163
/// Byte size representation.
150
164
#[ derive( Copy , Clone , PartialEq , PartialOrd , Eq , Ord , Hash , Default ) ]
151
165
pub struct ByteSize ( pub u64 ) ;
@@ -217,6 +231,18 @@ impl ByteSize {
217
231
ByteSize ( size * PIB )
218
232
}
219
233
234
+ /// Constructs a byte size wrapper from a quantity of exabytes.
235
+ #[ inline( always) ]
236
+ pub const fn eb ( size : u64 ) -> ByteSize {
237
+ ByteSize ( size * EB )
238
+ }
239
+
240
+ /// Constructs a byte size wrapper from a quantity of exbibytes.
241
+ #[ inline( always) ]
242
+ pub const fn eib ( size : u64 ) -> ByteSize {
243
+ ByteSize ( size * EIB )
244
+ }
245
+
220
246
/// Returns byte count.
221
247
#[ inline( always) ]
222
248
pub const fn as_u64 ( & self ) -> u64 {
@@ -459,6 +485,7 @@ mod tests {
459
485
assert ! ( ByteSize :: mb( 1 ) != ByteSize :: kib( 1024 ) ) ;
460
486
assert ! ( ByteSize :: mb( 1 ) < ByteSize :: kib( 1024 ) ) ;
461
487
assert ! ( ByteSize :: b( 0 ) < ByteSize :: tib( 1 ) ) ;
488
+ assert ! ( ByteSize :: pib( 1 ) < ByteSize :: eb( 1 ) ) ;
462
489
}
463
490
464
491
#[ track_caller]
@@ -475,6 +502,7 @@ mod tests {
475
502
assert_display ( "518.0 GiB" , ByteSize :: gib ( 518 ) ) ;
476
503
assert_display ( "815.0 TiB" , ByteSize :: tib ( 815 ) ) ;
477
504
assert_display ( "609.0 PiB" , ByteSize :: pib ( 609 ) ) ;
505
+ assert_display ( "15.0 EiB" , ByteSize :: eib ( 15 ) ) ;
478
506
}
479
507
480
508
#[ test]
0 commit comments