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§
Implementations§
Source§impl Endianness
impl Endianness
Sourcepub fn native() -> Endianness
pub fn native() -> Endianness
Obtains this system’s native endianness.
On this platform, the function returns Endianness::Little
.
Sourcepub fn le_iff(e: bool) -> Endianness
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);
Sourcepub fn be_iff(e: bool) -> Endianness
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);
Sourcepub fn to_opposite(self) -> Endianness
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
impl Clone for Endianness
Source§fn clone(&self) -> Endianness
fn clone(&self) -> Endianness
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for Endianness
impl Debug for Endianness
Source§impl Endian for Endianness
impl Endian for Endianness
Source§type Opposite = 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
fn into_opposite(self) -> <Endianness as Endian>::Opposite
Converts the receiver into its opposite.
Source§fn is_native(self) -> bool
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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§impl From<Endianness> for BasicDecoder
impl From<Endianness> for BasicDecoder
Source§fn from(endianness: Endianness) -> Self
fn from(endianness: Endianness) -> Self
Converts to this type from the input type.
Source§impl From<StaticEndianness<BigEndian>> for Endianness
impl From<StaticEndianness<BigEndian>> for Endianness
Source§fn from(_: StaticEndianness<BigEndian>) -> Endianness
fn from(_: StaticEndianness<BigEndian>) -> Endianness
Converts to this type from the input type.
Source§impl From<StaticEndianness<LittleEndian>> for Endianness
impl From<StaticEndianness<LittleEndian>> for Endianness
Source§fn from(_: StaticEndianness<LittleEndian>) -> Endianness
fn from(_: StaticEndianness<LittleEndian>) -> Endianness
Converts to this type from the input type.
Source§impl Hash for Endianness
impl Hash for Endianness
Source§impl Ord for Endianness
impl Ord for Endianness
Source§fn cmp(&self, other: &Endianness) -> Ordering
fn cmp(&self, other: &Endianness) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl PartialEq<StaticEndianness<BigEndian>> for Endianness
impl PartialEq<StaticEndianness<BigEndian>> for Endianness
Source§impl PartialEq<StaticEndianness<LittleEndian>> for Endianness
impl PartialEq<StaticEndianness<LittleEndian>> for Endianness
Source§impl PartialEq for Endianness
impl PartialEq for Endianness
Source§impl PartialOrd for Endianness
impl PartialOrd for Endianness
impl Copy for Endianness
impl Eq for Endianness
impl StructuralPartialEq for Endianness
Auto Trait Implementations§
impl Freeze for Endianness
impl RefUnwindSafe for Endianness
impl Send for Endianness
impl Sync for Endianness
impl Unpin for Endianness
impl UnwindSafe for Endianness
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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