Enum byte_unit::ByteUnit

source ·
pub enum ByteUnit {
Show 15 variants B, KB, KiB, MB, MiB, GB, GiB, TB, TiB, PB, PiB, EB, EiB, ZB, ZiB,
}
Expand description

The unit of bytes.

Variants§

§

B

1 B = 1 byte

§

KB

1 KB = 1000 bytes (103)

§

KiB

1 KiB = 1024 bytes (210)

§

MB

1 MB = 1000000 bytes (106)

§

MiB

1 MiB = 1048576 bytes (220)

§

GB

1 GB = 1000000000 bytes (109)

§

GiB

1 GiB = 1073741824 bytes (230)

§

TB

1 TB = 1000000000000 bytes (1012)

§

TiB

1 TiB = 1099511627776 bytes (240)

§

PB

1 PB = 1000000000000000 bytes (1015)

§

PiB

1 PiB = 1125899906842624 bytes (250)

§

EB

1 EB = 1000000000000000000 bytes (1018)

§

EiB

1 EiB = 1152921504606846976 bytes (260)

§

ZB

1 ZB = 1000000000000000000000 bytes (1021)

§

ZiB

1 ZiB = 1180591620717411303424 bytes (270)

Implementations§

source§

impl ByteUnit

source

pub fn from_str<S: AsRef<str>>(unit: S) -> Result<ByteUnit, UnitIncorrectError>

Get an instance of ByteUnit from a string slice.

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());
source

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

Use string slice to represent this ByteUnit.

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());
source

pub fn get_unit_bytes(self) -> u128

Get bytes represented by this ByteUnit.

use byte_unit::ByteUnit;

assert_eq!(1000000000000000000000, ByteUnit::ZB.get_unit_bytes());
assert_eq!(1152921504606846976, ByteUnit::EiB.get_unit_bytes());

Trait Implementations§

source§

impl AsRef<str> for ByteUnit

source§

fn as_ref(&self) -> &str

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl Clone for ByteUnit

source§

fn clone(&self) -> ByteUnit

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for ByteUnit

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'de> Deserialize<'de> for ByteUnit

source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Display for ByteUnit

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl FromStr for ByteUnit

§

type Err = UnitIncorrectError

The associated error which can be returned from parsing.
source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
source§

impl PartialEq<ByteUnit> for ByteUnit

source§

fn eq(&self, other: &ByteUnit) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for ByteUnit

source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>where S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl TryFrom<&str> for ByteUnit

§

type Error = UnitIncorrectError

The type returned in the event of a conversion error.
source§

fn try_from(s: &str) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl Copy for ByteUnit

source§

impl Eq for ByteUnit

source§

impl StructuralEq for ByteUnit

source§

impl StructuralPartialEq for ByteUnit

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,