Struct zng_unit::ByteLength

source ·
pub struct ByteLength(pub usize);
Expand description

A length in bytes.

The value is stored in bytes, you can use associated functions to convert from other units or you can use the ByteUnits extension methods to initialize from an integer literal.

Tuple Fields§

§0: usize

Implementations§

source§

impl ByteLength

source

pub fn bytes(&self) -> usize

Length in bytes.

This is the same as .0.

source

pub fn kibis(self) -> f64

Length in kibi-bytes.

source

pub fn kilos(self) -> f64

Length in kilo-bytes.

source

pub fn mebis(self) -> f64

Length in mebi-bytes.

source

pub fn megas(self) -> f64

Length in mega-bytes.

source

pub fn gibis(self) -> f64

Length in gibi-bytes.

source

pub fn gigas(self) -> f64

Length in giga-bytes.

source

pub fn tebis(self) -> f64

Length in tebi-bytes.

source

pub fn teras(self) -> f64

Length in tera-bytes.

source

pub const MAX: ByteLength = _

Maximum representable byte length.

source

pub const fn saturating_add(self, rhs: ByteLength) -> ByteLength

Adds the two lengths without overflowing or wrapping.

source

pub const fn saturating_sub(self, rhs: ByteLength) -> ByteLength

Subtracts the two lengths without overflowing or wrapping.

source

pub const fn saturating_mul(self, rhs: ByteLength) -> ByteLength

Multiplies the two lengths without overflowing or wrapping.

source

pub const fn wrapping_add(self, rhs: ByteLength) -> ByteLength

Adds the two lengths wrapping overflows.

source

pub const fn wrapping_sub(self, rhs: ByteLength) -> ByteLength

Subtracts the two lengths wrapping overflows.

source

pub const fn wrapping_mul(self, rhs: ByteLength) -> ByteLength

Multiplies the two lengths wrapping overflows.

source

pub const fn wrapping_div(self, rhs: ByteLength) -> ByteLength

Divides the two lengths wrapping overflows.

source

pub fn checked_add(self, rhs: ByteLength) -> Option<ByteLength>

Adds the two lengths, returns None if the sum overflows.

source

pub fn checked_sub(self, rhs: ByteLength) -> Option<ByteLength>

Subtracts the two lengths, returns None if the subtraction overflows.

source

pub fn checked_mul(self, rhs: ByteLength) -> Option<ByteLength>

Multiplies the two lengths, returns None if the sum overflows.

source

pub fn checked_div(self, rhs: ByteLength) -> Option<ByteLength>

Divides the two lengths, returns None if the subtraction overflows.

source§

impl ByteLength

Constructors

source

pub const fn from_byte(bytes: usize) -> Self

From bytes.

This is the same as ByteLength(bytes).

source

pub const fn from_kibi(kibi_bytes: usize) -> Self

From kibi-bytes.

1 kibi-byte equals 1024 bytes.

source

pub const fn from_kilo(kibi_bytes: usize) -> Self

From kilo-bytes.

1 kilo-byte equals 1000 bytes.

source

pub const fn from_mebi(mebi_bytes: usize) -> Self

From mebi-bytes.

1 mebi-byte equals 1024² bytes.

source

pub const fn from_mega(mebi_bytes: usize) -> Self

From mega-bytes.

1 mega-byte equals 1000² bytes.

source

pub const fn from_gibi(gibi_bytes: usize) -> Self

From gibi-bytes.

1 gibi-byte equals 1024³ bytes.

source

pub const fn from_giga(giga_bytes: usize) -> Self

From giga-bytes.

1 giga-byte equals 1000³ bytes.

source

pub const fn from_tebi(gibi_bytes: usize) -> Self

From tebi-bytes.

1 tebi-byte equals 1024^4 bytes.

source

pub const fn from_tera(tera_bytes: usize) -> Self

From tera-bytes.

1 tera-byte equals 1000^4 bytes.

source§

impl ByteLength

source

pub fn max(self, other: Self) -> Self

Compares and returns the maximum of two lengths.

source

pub fn min(self, other: Self) -> Self

Compares and returns the minimum of two lengths.

Trait Implementations§

source§

impl Add for ByteLength

source§

type Output = ByteLength

The resulting type after applying the + operator.
source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
source§

impl AddAssign for ByteLength

source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
source§

impl Clone for ByteLength

source§

fn clone(&self) -> ByteLength

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 ByteLength

source§

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

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

impl Default for ByteLength

source§

fn default() -> ByteLength

Returns the “default value” for a type. Read more
source§

impl<'de> Deserialize<'de> for ByteLength

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 ByteLength

source§

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

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

impl<S: Into<Factor>> Div<S> for ByteLength

source§

type Output = ByteLength

The resulting type after applying the / operator.
source§

fn div(self, rhs: S) -> Self

Performs the / operation. Read more
source§

impl<S: Into<Factor>> DivAssign<S> for ByteLength

source§

fn div_assign(&mut self, rhs: S)

Performs the /= operation. Read more
source§

impl From<usize> for ByteLength

source§

fn from(value: usize) -> Self

Converts to this type from the input type.
source§

impl Hash for ByteLength

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<S: Into<Factor>> Mul<S> for ByteLength

source§

type Output = ByteLength

The resulting type after applying the * operator.
source§

fn mul(self, rhs: S) -> Self

Performs the * operation. Read more
source§

impl<S: Into<Factor>> MulAssign<S> for ByteLength

source§

fn mul_assign(&mut self, rhs: S)

Performs the *= operation. Read more
source§

impl Ord for ByteLength

source§

fn cmp(&self, other: &ByteLength) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for ByteLength

source§

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

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

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

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

impl PartialOrd for ByteLength

source§

fn partial_cmp(&self, other: &ByteLength) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Serialize for ByteLength

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 Sub for ByteLength

source§

type Output = ByteLength

The resulting type after applying the - operator.
source§

fn sub(self, rhs: Self) -> Self::Output

Performs the - operation. Read more
source§

impl SubAssign for ByteLength

source§

fn sub_assign(&mut self, rhs: Self)

Performs the -= operation. Read more
source§

impl Copy for ByteLength

source§

impl Eq for ByteLength

source§

impl StructuralPartialEq for ByteLength

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

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 T
where T: Clone,

source§

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 T
where 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 T
where U: Into<T>,

source§

type Error = Infallible

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

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

Performs the conversion.
source§

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

source§

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

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

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

Performs the conversion.
source§

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