Struct dicom_core::header::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 substraction 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<i32> for Length

§

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 Add for Length

§

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 Clone for Length

source§

fn clone(&self) -> Length

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 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

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 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 · source§

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

This method 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

This method 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

This method 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

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

impl Sub<i32> for Length

§

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

§

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 SubAssign<i32> for Length

source§

fn sub_assign(&mut self, rhs: i32)

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 Copy for Length

Auto Trait Implementations§

§

impl Freeze for Length

§

impl RefUnwindSafe for Length

§

impl Send for Length

§

impl Sync for Length

§

impl Unpin for Length

§

impl UnwindSafe for Length

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> 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,

§

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>,

§

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>,

§

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.