Trait rocket::data::ToByteUnit
source · pub trait ToByteUnit: Into<ByteUnit> {
Show 13 methods
// Provided methods
fn bytes(self) -> ByteUnit { ... }
fn kilobytes(self) -> ByteUnit { ... }
fn kibibytes(self) -> ByteUnit { ... }
fn megabytes(self) -> ByteUnit { ... }
fn mebibytes(self) -> ByteUnit { ... }
fn gigabytes(self) -> ByteUnit { ... }
fn gibibytes(self) -> ByteUnit { ... }
fn terabytes(self) -> ByteUnit { ... }
fn tibibytes(self) -> ByteUnit { ... }
fn petabytes(self) -> ByteUnit { ... }
fn pebibytes(self) -> ByteUnit { ... }
fn exabytes(self) -> ByteUnit { ... }
fn exbibytes(self) -> ByteUnit { ... }
}
Expand description
Extension trait for conversion from integer types to ByteUnit
.
The ToByteUnit
trait provides methods on integer types that convert the
integer type into the ByteUnit
unit represented by the method name. To
use the trait, simply import it. The trait is implemented for all integer
types.
As with all other ByteUnit
operations, conversions saturate.
§Example
use ubyte::ToByteUnit;
assert_eq!(512.kilobytes(), 512000.bytes());
assert_eq!(512.kibibytes(), 524288.bytes());
assert_eq!(512.kilobytes(), 512 * 1.kilobytes());
assert_eq!(1000.bytes(), 1.kilobytes());
assert_eq!(1000.bytes() + 24, 1.kibibytes());
assert_eq!(2048.mebibytes(), 2.gibibytes());
assert!(2.megabytes() + 500.kilobytes() > 2.mebibytes());
assert!(2.pebibytes() > 2.petabytes());
// As with other `ByteUnit` operations, conversions saturate.
assert_eq!((1 << 10).exbibytes(), (1 << 20).exbibytes());
Provided Methods§
Object Safety§
This trait is not object safe.