Enum dicom_encoding::transfer_syntax::Endianness

source ·
pub enum Endianness {
    Little,
    Big,
}
Expand description

Enumerate for materializing the two kinds of machine byte order supported by Rust in a dynamic fashion. That is, the information of whether to read or write data in Little Endian or in Big Endian is resolved at run time by observing this value.

Using this type as the generic endianness type E in a ByteOrdered is useful when this information can only be retrieved from a source that is unknown to the compiler.

Variants§

§

Little

Little Endian

§

Big

Big Endian

Implementations§

source§

impl Endianness

source

pub fn native() -> Endianness

Obtains this system’s native endianness.

On this platform, the function returns Endianness::Little.

source

pub fn le_iff(e: bool) -> Endianness

Obtains Little Endian if and only if the given value is true.

§Examples
let data: &[u8] = &[4, 1];
let e = Endianness::le_iff(2 + 2 == 4);
assert_eq!(e.read_u16(data).unwrap(), 260);

let e = Endianness::le_iff(2 + 2 >= 5);
assert_eq!(e.read_u16(data).unwrap(), 1025);
source

pub fn be_iff(e: bool) -> Endianness

Obtains Big Endian if and only if the given value is true.

Examples

assert_eq!(Endianness::be_iff(2 + 2 == 4), Endianness::Big);
assert_eq!(Endianness::be_iff(2 + 2 >= 5), Endianness::Little);
source

pub fn to_opposite(self) -> Endianness

Obtains the opposite endianness: Little Endian returns Big Endian and vice versa.

Trait Implementations§

source§

impl Clone for Endianness

source§

fn clone(&self) -> Endianness

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 Endianness

source§

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

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

impl Endian for Endianness

§

type Opposite = Endianness

A type which can represent a byte order that is opposite to this one.
source§

fn into_opposite(self) -> <Endianness as Endian>::Opposite

Converts the receiver into its opposite.
source§

fn is_native(self) -> bool

Checks whether this value represents the system’s native endianness.
source§

fn read_i16<S>(self, src: S) -> Result<i16, Error>
where S: Read,

Reads a signed 16 bit integer from the given reader. Read more
source§

fn read_u16<S>(self, src: S) -> Result<u16, Error>
where S: Read,

Reads an unsigned 16 bit integer from the given reader. Read more
source§

fn read_i32<S>(self, src: S) -> Result<i32, Error>
where S: Read,

Reads a signed 32 bit integer from the given reader. Read more
source§

fn read_u32<S>(self, src: S) -> Result<u32, Error>
where S: Read,

Reads an unsigned 32 bit integer from the given reader. Read more
source§

fn read_i64<S>(self, src: S) -> Result<i64, Error>
where S: Read,

Reads a signed 64 bit integer from the given reader. Read more
source§

fn read_u64<S>(self, src: S) -> Result<u64, Error>
where S: Read,

Reads an unsigned 64 bit integer from the given reader. Read more
source§

fn read_f32<S>(self, src: S) -> Result<f32, Error>
where S: Read,

Reads a IEEE754 single-precision (4 bytes) floating point number from the given reader. Read more
source§

fn read_f64<S>(self, src: S) -> Result<f64, Error>
where S: Read,

Reads a IEEE754 double-precision (8 bytes) floating point number from the given reader. Read more
source§

fn read_i128<S>(self, src: S) -> Result<i128, Error>
where S: Read,

Reads a signed 128 bit integer from the given reader. Read more
source§

fn read_u128<S>(self, src: S) -> Result<u128, Error>
where S: Read,

Reads an unsigned 128 bit integer from the given reader. Read more
source§

fn read_i16_into<S>(self, src: S, dst: &mut [i16]) -> Result<(), Error>
where S: Read,

Reads a sequence of signed 16 bit integers from the given reader. Read more
source§

fn read_u16_into<S>(self, src: S, dst: &mut [u16]) -> Result<(), Error>
where S: Read,

Reads a sequence of unsigned 16 bit integers from the given reader. Read more
source§

fn read_i32_into<S>(self, src: S, dst: &mut [i32]) -> Result<(), Error>
where S: Read,

Reads a sequence of signed 32 bit integers from the given reader. Read more
source§

fn read_u32_into<S>(self, src: S, dst: &mut [u32]) -> Result<(), Error>
where S: Read,

Reads a sequence of unsigned 32 bit integers from the given reader. Read more
source§

fn read_i64_into<S>(self, src: S, dst: &mut [i64]) -> Result<(), Error>
where S: Read,

Reads a sequence of signed 64 bit integers from the given reader. Read more
source§

fn read_u64_into<S>(self, src: S, dst: &mut [u64]) -> Result<(), Error>
where S: Read,

Reads a sequence of unsigned 64 bit integers from the given reader. Read more
source§

fn read_f32_into<S>(self, src: S, dst: &mut [f32]) -> Result<(), Error>
where S: Read,

Reads a sequence of IEEE754 single-precision (4 bytes) floating point numbers from the given reader. Read more
source§

fn read_f64_into<S>(self, src: S, dst: &mut [f64]) -> Result<(), Error>
where S: Read,

Reads a sequence of IEEE754 double-precision (8 bytes) floating point numbers from the given reader. Read more
source§

fn read_i128_into<S>(self, src: S, dst: &mut [i128]) -> Result<(), Error>
where S: Read,

Reads a sequence of signed 128 bit integers from the given reader. Read more
source§

fn read_u128_into<S>(self, src: S, dst: &mut [u128]) -> Result<(), Error>
where S: Read,

Reads a sequence of unsigned 128 bit integers from the given reader. Read more
source§

fn write_i16<S>(self, src: S, v: i16) -> Result<(), Error>
where S: Write,

Writes a signed 16 bit integer to the given writer. Read more
source§

fn write_u16<S>(self, src: S, v: u16) -> Result<(), Error>
where S: Write,

Writes an unsigned 16 bit integer to the given writer. Read more
source§

fn write_i32<S>(self, src: S, v: i32) -> Result<(), Error>
where S: Write,

Writes a signed 32 bit integer to the given writer. Read more
source§

fn write_u32<S>(self, src: S, v: u32) -> Result<(), Error>
where S: Write,

Writes an unsigned 32 bit integer to the given writer. Read more
source§

fn write_i64<S>(self, src: S, v: i64) -> Result<(), Error>
where S: Write,

Writes a signed 64 bit integer to the given writer. Read more
source§

fn write_u64<S>(self, src: S, v: u64) -> Result<(), Error>
where S: Write,

Writes an unsigned 64 bit integer to the given writer. Read more
source§

fn write_f32<S>(self, src: S, v: f32) -> Result<(), Error>
where S: Write,

Writes a IEEE754 single-precision (4 bytes) floating point number to the given writer. Read more
source§

fn write_f64<S>(self, src: S, v: f64) -> Result<(), Error>
where S: Write,

Writes a IEEE754 double-precision (8 bytes) floating point number to the given writer. Read more
source§

fn write_i128<S>(self, src: S, v: i128) -> Result<(), Error>
where S: Write,

Writes a signed 128 bit integer to the given writer. Read more
source§

fn write_u128<S>(self, src: S, v: u128) -> Result<(), Error>
where S: Write,

Writes an unsigned 128 bit integer to the given writer. Read more
source§

impl From<Endianness> for BasicDecoder

source§

fn from(endianness: Endianness) -> Self

Converts to this type from the input type.
source§

impl From<StaticEndianness<BigEndian>> for Endianness

source§

fn from(_: StaticEndianness<BigEndian>) -> Endianness

Converts to this type from the input type.
source§

impl From<StaticEndianness<LittleEndian>> for Endianness

source§

fn from(_: StaticEndianness<LittleEndian>) -> Endianness

Converts to this type from the input type.
source§

impl Hash for Endianness

source§

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

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 Ord for Endianness

source§

fn cmp(&self, other: &Endianness) -> 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<StaticEndianness<BigEndian>> for Endianness

source§

fn eq(&self, _: &StaticEndianness<BigEndian>) -> 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 PartialEq<StaticEndianness<LittleEndian>> for Endianness

source§

fn eq(&self, _: &StaticEndianness<LittleEndian>) -> 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 PartialEq for Endianness

source§

fn eq(&self, other: &Endianness) -> 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 Endianness

source§

fn partial_cmp(&self, other: &Endianness) -> 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 Copy for Endianness

source§

impl Eq for Endianness

source§

impl StructuralPartialEq for Endianness

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