rocket::data

Trait 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§

Source

fn bytes(self) -> ByteUnit

Converts self to a ByteUnit representing self bytes.

Source

fn kilobytes(self) -> ByteUnit

Converts self to a ByteUnit representing self kB .

Source

fn kibibytes(self) -> ByteUnit

Converts self to a ByteUnit representing self KiB .

Source

fn megabytes(self) -> ByteUnit

Converts self to a ByteUnit representing self MB .

Source

fn mebibytes(self) -> ByteUnit

Converts self to a ByteUnit representing self MiB .

Source

fn gigabytes(self) -> ByteUnit

Converts self to a ByteUnit representing self GB .

Source

fn gibibytes(self) -> ByteUnit

Converts self to a ByteUnit representing self GiB .

Source

fn terabytes(self) -> ByteUnit

Converts self to a ByteUnit representing self TB .

Source

fn tibibytes(self) -> ByteUnit

Converts self to a ByteUnit representing self TiB .

Source

fn petabytes(self) -> ByteUnit

Converts self to a ByteUnit representing self PB .

Source

fn pebibytes(self) -> ByteUnit

Converts self to a ByteUnit representing self PiB .

Source

fn exabytes(self) -> ByteUnit

Converts self to a ByteUnit representing self EB .

Source

fn exbibytes(self) -> ByteUnit

Converts self to a ByteUnit representing self EiB .

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<T> ToByteUnit for T
where T: Into<ByteUnit> + Copy,