[][src]Enum byte_unit::ByteUnit

pub enum ByteUnit {
    B,
    KB,
    KiB,
    MB,
    MiB,
    GB,
    GiB,
    TB,
    TiB,
    PB,
    PiB,
}

The unit of bytes.

Variants

B

1 B = 1 byte

KB

1 KB = 1000 bytes

KiB

1 KiB = 1024 bytes

MB

1 MB = 1000000 bytes

MiB

1 MiB = 1048576 bytes

GB

1 GB = 1000000000 bytes

GiB

1 GiB = 1073741824 bytes

TB

1 TB = 1000000000000 bytes

TiB

1 TiB = 1099511627776 bytes

PB

1 PB = 1000000000000000 bytes

PiB

1 PiB = 1125899906842624 bytes

Methods

impl ByteUnit[src]

pub fn from_str<S: AsRef<str>>(unit: S) -> Result<ByteUnit, ByteError>[src]

Get an instance of ByteUnit from a string slice.

extern crate byte_unit;

use byte_unit::ByteUnit;

assert_eq!(ByteUnit::B, ByteUnit::from_str("").unwrap());
assert_eq!(ByteUnit::B, ByteUnit::from_str("b").unwrap());
assert_eq!(ByteUnit::B, ByteUnit::from_str("B").unwrap());
assert_eq!(ByteUnit::KB, ByteUnit::from_str("k").unwrap());
assert_eq!(ByteUnit::KB, ByteUnit::from_str("K").unwrap());
assert_eq!(ByteUnit::KiB, ByteUnit::from_str("Kib").unwrap());
assert_eq!(ByteUnit::MB, ByteUnit::from_str("mb").unwrap());
assert_eq!(ByteUnit::MiB, ByteUnit::from_str("mib").unwrap());
assert_eq!(ByteUnit::GB, ByteUnit::from_str("GB").unwrap());
assert_eq!(ByteUnit::GiB, ByteUnit::from_str("GiB").unwrap());
assert_eq!(ByteUnit::TB, ByteUnit::from_str("TB").unwrap());
assert_eq!(ByteUnit::TiB, ByteUnit::from_str("TIB").unwrap());
assert_eq!(ByteUnit::PB, ByteUnit::from_str("PB").unwrap());
assert_eq!(ByteUnit::PiB, ByteUnit::from_str("PiB").unwrap());

pub fn as_str(self) -> &'static str[src]

Use string slice to represent this ByteUnit.

extern crate byte_unit;

use byte_unit::ByteUnit;

assert_eq!("B", ByteUnit::B.as_str());
assert_eq!("KB", ByteUnit::KB.as_str());
assert_eq!("KiB", ByteUnit::KiB.as_str());
assert_eq!("MB", ByteUnit::MB.as_str());
assert_eq!("MiB", ByteUnit::MiB.as_str());
assert_eq!("GB", ByteUnit::GB.as_str());
assert_eq!("GiB", ByteUnit::GiB.as_str());
assert_eq!("TB", ByteUnit::TB.as_str());
assert_eq!("TiB", ByteUnit::TiB.as_str());
assert_eq!("PB", ByteUnit::PB.as_str());
assert_eq!("PiB", ByteUnit::PiB.as_str());

Trait Implementations

impl Debug for ByteUnit[src]

impl Display for ByteUnit[src]

impl PartialEq<ByteUnit> for ByteUnit[src]

impl Eq for ByteUnit[src]

impl Copy for ByteUnit[src]

impl FromStr for ByteUnit[src]

type Err = ByteError

The associated error which can be returned from parsing.

impl AsRef<str> for ByteUnit[src]

impl Clone for ByteUnit[src]

Auto Trait Implementations

impl Unpin for ByteUnit

impl Send for ByteUnit

impl Sync for ByteUnit

Blanket Implementations

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]