22//!
33//! Features:
44//!
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 ).
66//! - `ByteSize` type which presents size units convertible to different size units.
77//! - Arithmetic operations for `ByteSize`.
88//! - `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;
6868pub const TB : u64 = 1_000_000_000_000 ;
6969/// Number of bytes in 1 petabyte.
7070pub 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 ;
7173
7274/// Number of bytes in 1 kibibyte.
7375pub const KIB : u64 = 1_024 ;
@@ -79,6 +81,8 @@ pub const GIB: u64 = 1_073_741_824;
7981pub const TIB : u64 = 1_099_511_627_776 ;
8082/// Number of bytes in 1 pebibyte.
8183pub 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 ;
8286
8387/// IEC (binary) units.
8488///
@@ -146,6 +150,16 @@ pub fn pib<V: Into<u64>>(size: V) -> u64 {
146150 size. into ( ) * PIB
147151}
148152
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+
149163/// Byte size representation.
150164#[ derive( Copy , Clone , PartialEq , PartialOrd , Eq , Ord , Hash , Default ) ]
151165pub struct ByteSize ( pub u64 ) ;
@@ -217,6 +231,18 @@ impl ByteSize {
217231 ByteSize ( size * PIB )
218232 }
219233
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+
220246 /// Returns byte count.
221247 #[ inline( always) ]
222248 pub const fn as_u64 ( & self ) -> u64 {
@@ -459,6 +485,7 @@ mod tests {
459485 assert ! ( ByteSize :: mb( 1 ) != ByteSize :: kib( 1024 ) ) ;
460486 assert ! ( ByteSize :: mb( 1 ) < ByteSize :: kib( 1024 ) ) ;
461487 assert ! ( ByteSize :: b( 0 ) < ByteSize :: tib( 1 ) ) ;
488+ assert ! ( ByteSize :: pib( 1 ) < ByteSize :: eb( 1 ) ) ;
462489 }
463490
464491 #[ track_caller]
@@ -475,6 +502,7 @@ mod tests {
475502 assert_display ( "518.0 GiB" , ByteSize :: gib ( 518 ) ) ;
476503 assert_display ( "815.0 TiB" , ByteSize :: tib ( 815 ) ) ;
477504 assert_display ( "609.0 PiB" , ByteSize :: pib ( 609 ) ) ;
505+ assert_display ( "15.0 EiB" , ByteSize :: eib ( 15 ) ) ;
478506 }
479507
480508 #[ test]
0 commit comments