Skip to main content

Length

Struct Length 

Source
pub struct Length(pub u32);
Expand description

A type for representing data set content length, in bytes. An internal value of 0xFFFF_FFFF represents an undefined (unspecified) length, which would have to be determined with a traversal based on the content’s encoding.

This also means that numeric comparisons and arithmetic do not function the same way as primitive number types:

Two length of undefined length are not equal.

assert_ne!(Length::UNDEFINED, Length::UNDEFINED);

Any addition or subtraction with at least one undefined length results in an undefined length.

assert!((Length::defined(64) + Length::UNDEFINED).is_undefined());
assert!((Length::UNDEFINED + 8).is_undefined());

Comparing between at least one undefined length is always false.

assert!(Length::defined(16) < Length::defined(64));
assert!(!(Length::UNDEFINED < Length::defined(64)));
assert!(!(Length::UNDEFINED > Length::defined(64)));

assert!(!(Length::UNDEFINED < Length::UNDEFINED));
assert!(!(Length::UNDEFINED > Length::UNDEFINED));
assert!(!(Length::UNDEFINED <= Length::UNDEFINED));
assert!(!(Length::UNDEFINED >= Length::UNDEFINED));

Tuple Fields§

§0: u32

Implementations§

Source§

impl Length

Source

pub const UNDEFINED: Self

A length that is undefined.

Source

pub fn new(len: u32) -> Self

Create a new length value from its internal representation. This is equivalent to Length(len).

Source

pub fn defined(len: u32) -> Self

Create a new length value with the given number of bytes.

§Panic

This function will panic if len represents an undefined length.

Source§

impl Length

Source

pub fn is_undefined(self) -> bool

Check whether this length is undefined (unknown).

Source

pub fn is_defined(self) -> bool

Check whether this length is well defined (not undefined).

Source

pub fn get(self) -> Option<u32>

Fetch the concrete length value, if available. Returns None if it represents an undefined length.

Source

pub fn inner_eq(self, other: Length) -> bool

Check whether the length is equally specified as another length. Unlike the implemented PartialEq, two undefined lengths are considered equivalent by this method.

Trait Implementations§

Source§

impl Add for Length

Source§

type Output = Length

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl Add<i32> for Length

Source§

type Output = Length

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl Clone for Length

Source§

fn clone(&self) -> Length

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for Length

Source§

impl Debug for Length

Source§

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

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

impl Display for Length

Source§

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

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

impl From<u32> for Length

Source§

fn from(o: u32) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Length

Source§

fn eq(&self, rhs: &Length) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 Length

Source§

fn partial_cmp(&self, rhs: &Length) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 Sub for Length

Source§

type Output = Length

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl Sub<i32> for Length

Source§

type Output = Length

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl SubAssign for Length

Source§

fn sub_assign(&mut self, rhs: Length)

Performs the -= operation. Read more
Source§

impl SubAssign<i32> for Length

Source§

fn sub_assign(&mut self, rhs: i32)

Performs the -= operation. Read more

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, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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§

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.