EndianValue

Enum EndianValue 

Source
pub enum EndianValue<T>
where T: SpecificEndian<T>,
{ Big(BigEndian<T>), Little(LittleEndian<T>), }
Available on crate feature io-core only.
Expand description

Read raw bytes into a BigEndian<T>.

Short helper; avoids _be/_le in the public API name.

Example:

use simple_endian::io::core_io;
let data: [u8; 2] = [0x12, 0x34];
let be: simple_endian::BigEndian<u16> = core_io::from_bytes(&data).unwrap();
assert_eq!(be.to_native(), 0x1234u16);

Zero-allocation enum that holds either a BigEndian<T> or LittleEndian<T> value. This replaces an earlier boxed trait-based approach to avoid heap allocation.

Variants§

§

Big(BigEndian<T>)

§

Little(LittleEndian<T>)

Implementations§

Source§

impl<T> EndianValue<T>
where T: SpecificEndian<T> + Copy,

Source

pub fn to_native(&self) -> T

Available on crate features io-core or io-std only.

Convert the stored endian wrapper into the host-native T.

Auto Trait Implementations§

§

impl<T> Freeze for EndianValue<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for EndianValue<T>
where T: RefUnwindSafe,

§

impl<T> Send for EndianValue<T>
where T: Send,

§

impl<T> Sync for EndianValue<T>
where T: Sync,

§

impl<T> Unpin for EndianValue<T>
where T: Unpin,

§

impl<T> UnwindSafe for EndianValue<T>
where T: UnwindSafe,

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