Trait pavex::unit::ToByteUnit

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§

fn bytes(self) -> ByteUnit

Converts self to a ByteUnit representing self bytes.

fn kilobytes(self) -> ByteUnit

Converts self to a ByteUnit representing self kB .

fn kibibytes(self) -> ByteUnit

Converts self to a ByteUnit representing self KiB .

fn megabytes(self) -> ByteUnit

Converts self to a ByteUnit representing self MB .

fn mebibytes(self) -> ByteUnit

Converts self to a ByteUnit representing self MiB .

fn gigabytes(self) -> ByteUnit

Converts self to a ByteUnit representing self GB .

fn gibibytes(self) -> ByteUnit

Converts self to a ByteUnit representing self GiB .

fn terabytes(self) -> ByteUnit

Converts self to a ByteUnit representing self TB .

fn tibibytes(self) -> ByteUnit

Converts self to a ByteUnit representing self TiB .

fn petabytes(self) -> ByteUnit

Converts self to a ByteUnit representing self PB .

fn pebibytes(self) -> ByteUnit

Converts self to a ByteUnit representing self PiB .

fn exabytes(self) -> ByteUnit

Converts self to a ByteUnit representing self EB .

fn exbibytes(self) -> ByteUnit

Converts self to a ByteUnit representing self EiB .

Object Safety§

This trait is not object safe.

Implementors§

§

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