Trait ubyte::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 .

Implementors§