Struct EndianPrimitive

Source
#[repr(C)]
pub struct EndianPrimitive<B, T: EndianConvert, Alignment = ()> { /* private fields */ }
Expand description

A POD container for a primitive that stores a value in the specified endianness in memory, and transforms on get/set

Implementations§

Source§

impl<B: ByteOrder, T: EndianConvert, A> EndianPrimitive<B, T, A>

Source

pub fn new(v: T) -> Self

Creates a new value

Source

pub fn get(&self) -> T

Transforms to the native value

Source

pub fn set(&mut self, v: T)

Transforms from a native value

Source

pub fn raw(&self) -> &T::Unaligned

Gets the inner untransformed value

Source

pub fn raw_mut(&mut self) -> &mut T::Unaligned

A mutable reference to the inner untransformed value

Trait Implementations§

Source§

impl<B, T: EndianConvert, A> Clone for EndianPrimitive<B, T, A>

Source§

fn clone(&self) -> Self

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<B: ByteOrder, T: Debug + EndianConvert, A> Debug for EndianPrimitive<B, T, A>

Source§

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

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

impl<B: ByteOrder, T: Default + EndianConvert, A> Default for EndianPrimitive<B, T, A>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<B: ByteOrder, T: EndianConvert, A> From<T> for EndianPrimitive<B, T, A>

Source§

fn from(v: T) -> Self

Converts to this type from the input type.
Source§

impl<B, T: EndianConvert + Hash, A> Hash for EndianPrimitive<B, T, A>
where T::Unaligned: Hash,

Source§

fn hash<H: Hasher>(&self, h: &mut H)

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<T, B: ByteOrder, A> Into<*const T> for EndianPrimitive<B, *const T, A>

Source§

fn into(self) -> *const T

Converts this type into the (usually inferred) input type.
Source§

impl<T, B: ByteOrder, A> Into<*mut T> for EndianPrimitive<B, *mut T, A>

Source§

fn into(self) -> *mut T

Converts this type into the (usually inferred) input type.
Source§

impl<B: ByteOrder, A> Into<bool> for EndianPrimitive<B, bool, A>

Source§

fn into(self) -> bool

Converts this type into the (usually inferred) input type.
Source§

impl<B: ByteOrder, A> Into<f32> for EndianPrimitive<B, f32, A>

Source§

fn into(self) -> f32

Converts this type into the (usually inferred) input type.
Source§

impl<B: ByteOrder, A> Into<f64> for EndianPrimitive<B, f64, A>

Source§

fn into(self) -> f64

Converts this type into the (usually inferred) input type.
Source§

impl<B: ByteOrder, A> Into<i16> for EndianPrimitive<B, i16, A>

Source§

fn into(self) -> i16

Converts this type into the (usually inferred) input type.
Source§

impl<B: ByteOrder, A> Into<i32> for EndianPrimitive<B, i32, A>

Source§

fn into(self) -> i32

Converts this type into the (usually inferred) input type.
Source§

impl<B: ByteOrder, A> Into<i64> for EndianPrimitive<B, i64, A>

Source§

fn into(self) -> i64

Converts this type into the (usually inferred) input type.
Source§

impl<B: ByteOrder, A> Into<isize> for EndianPrimitive<B, isize, A>

Source§

fn into(self) -> isize

Converts this type into the (usually inferred) input type.
Source§

impl<B: ByteOrder, A> Into<u16> for EndianPrimitive<B, u16, A>

Source§

fn into(self) -> u16

Converts this type into the (usually inferred) input type.
Source§

impl<B: ByteOrder, A> Into<u32> for EndianPrimitive<B, u32, A>

Source§

fn into(self) -> u32

Converts this type into the (usually inferred) input type.
Source§

impl<B: ByteOrder, A> Into<u64> for EndianPrimitive<B, u64, A>

Source§

fn into(self) -> u64

Converts this type into the (usually inferred) input type.
Source§

impl<B: ByteOrder, A> Into<usize> for EndianPrimitive<B, usize, A>

Source§

fn into(self) -> usize

Converts this type into the (usually inferred) input type.
Source§

impl<B: ByteOrder, T: EndianConvert + Ord, A> Ord for EndianPrimitive<B, T, A>

Source§

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

Restrict a value to a certain interval. Read more
Source§

impl<ARHS, A, BRHS: ByteOrder, RHS: EndianConvert, B: ByteOrder, T: EndianConvert + PartialEq<RHS>> PartialEq<EndianPrimitive<BRHS, RHS, ARHS>> for EndianPrimitive<B, T, A>

Source§

fn eq(&self, other: &EndianPrimitive<BRHS, RHS, ARHS>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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<ARHS, A, BRHS: ByteOrder, RHS: EndianConvert, B: ByteOrder, T: EndianConvert + PartialOrd<RHS>> PartialOrd<EndianPrimitive<BRHS, RHS, ARHS>> for EndianPrimitive<B, T, A>

Source§

fn partial_cmp( &self, other: &EndianPrimitive<BRHS, RHS, ARHS>, ) -> 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

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

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

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<B: Pod, T: EndianConvert, A> Pod for EndianPrimitive<B, T, A>

Source§

unsafe fn uninitialized() -> Self

Generates a new uninitialized instance of a POD type.
Source§

fn zeroed() -> Self

Creates a new zeroed instance of a POD type.
Source§

fn copy(&self) -> Self

Creates a copy of this POD instance
Source§

fn map<T>(&self) -> Option<&T>
where T: Pod,

Converts a POD reference from one to another type of the same size. Read more
Source§

fn map_mut<T>(&mut self) -> Option<&mut T>
where T: Pod,

Converts a mutable POD reference from one to another type of the same size. Read more
Source§

fn map_copy<T>(&self) -> Option<T>
where T: Pod,

Converts a POD type from one to another of the same size. Read more
Source§

fn try_map<T>(&self) -> Option<&T>
where T: Pod,

Converts a POD reference from one to another type of the same or lesser size. Read more
Source§

fn try_map_mut<T>(&mut self) -> Option<&mut T>
where T: Pod,

Converts a mutable POD reference from one to another type of the same or lesser size. Read more
Source§

fn try_map_copy<T>(&self) -> Option<T>
where T: Pod,

Converts a POD type from one to another of the same or lesser size. Read more
Source§

fn map_box<T>(self: Box<Self>) -> Result<Box<T>, Box<Self>>
where T: Pod,

Converts a boxed POD type from one to another of the same size. Read more
Source§

fn split<T>(&self) -> Option<&[T]>
where T: Pod,

Converts a POD reference into a slice of another type. Read more
Source§

fn split_mut<T>(&mut self) -> Option<&mut [T]>
where T: Pod,

Converts a mutable POD reference into a slice of another type. Read more
Source§

fn try_split<T>(&self) -> &[T]
where T: Pod,

Converts a POD reference into a slice of another type. Read more
Source§

fn try_split_mut<T>(&mut self) -> &mut [T]
where T: Pod,

Converts a mutable POD reference into a slice of another type. Read more
Source§

fn split_box<T>(self: Box<Self>) -> Result<Box<[T]>, Box<Self>>
where T: Pod,

Converts a boxed POD object into a boxed slice of another type. Read more
Source§

fn split_vec<T>(self: Box<Self>) -> Result<Vec<T>, Box<Self>>
where T: Pod,

Converts a boxed POD object into a vector of another type. Read more
Source§

fn map_slice<T>(s: &[Self]) -> Option<&[T]>
where T: Pod,

Maps a POD slice from one type to another. Read more
Source§

fn map_slice_mut<T>(s: &mut [Self]) -> Option<&mut [T]>
where T: Pod,

Maps a mutable POD slice from one type to another. Read more
Source§

fn try_map_slice<T>(s: &[Self]) -> &[T]
where T: Pod,

Maps a POD slice from one type to another. Read more
Source§

fn try_map_slice_mut<T>(s: &mut [Self]) -> &mut [T]
where T: Pod,

Maps a mutable POD slice from one type to another. Read more
Source§

fn map_slice_box<T>(s: Box<[Self]>) -> Result<Box<[T]>, Box<[Self]>>
where T: Pod,

Maps a boxed POD slice from one type to another. Read more
Source§

fn map_slice_vec<T>(s: Vec<Self>) -> Result<Vec<T>, Vec<Self>>
where T: Pod,

Maps a POD vector from one type to another. Read more
Source§

fn merge<T>(s: &[Self]) -> Option<&T>
where T: Pod,

Converts a POD slice into another type. Read more
Source§

fn merge_mut<T>(s: &mut [Self]) -> Option<&mut T>
where T: Pod,

Converts a mutable POD slice into another type. Read more
Source§

fn merge_copy<T>(s: &[Self]) -> Option<T>
where T: Pod,

Converts a POD slice into another type. Read more
Source§

fn try_merge<T>(s: &[Self]) -> Option<&T>
where T: Pod,

Converts a POD slice into another type. Read more
Source§

fn try_merge_mut<T>(s: &mut [Self]) -> Option<&mut T>
where T: Pod,

Converts a mutable POD slice into another type. Read more
Source§

fn try_merge_copy<T>(s: &[Self]) -> Option<T>
where T: Pod,

Converts a POD slice into another type. Read more
Source§

fn merge_box<T>(s: Box<[Self]>) -> Result<Box<T>, Box<[Self]>>
where T: Pod,

Converts a boxed POD slice into another boxed type. Read more
Source§

fn merge_vec<T>(s: Vec<Self>) -> Result<Box<T>, Vec<Self>>
where T: Pod,

Converts a POD vector into another boxed type. Read more
Source§

unsafe fn from_ptr<T>(source: *const T) -> Self

Creates a new POD instance from an unaligned pointer. Read more
Source§

fn from_ref<T>(p: &T) -> Option<Self>
where T: Pod,

Creates a new POD instance with the inverse of map_copy()
Source§

fn from_slice<T>(p: &[T]) -> Option<Self>
where T: Pod,

Creates a new POD instance with the inverse of merge_copy()
Source§

fn from_boxed_slice<T>(p: Box<[T]>) -> Result<Box<Self>, Box<[T]>>
where T: Pod,

Creates a new POD instance with the inverse of merge_box()
Source§

fn from_vec<T>(p: Vec<T>) -> Result<Box<Self>, Vec<T>>
where T: Pod,

Creates a new POD instance with the inverse of merge_vec()
Source§

fn slice_from_boxed_slice<T>(p: Box<[T]>) -> Result<Box<[Self]>, Box<[T]>>
where T: Pod,

Creates a new POD instance with the inverse of map_slice_box()
Source§

fn ref_from<T>(p: &T) -> Option<&Self>
where T: Pod,

Creates a POD reference with the inverse of map()
Source§

fn ref_from_mut<T>(p: &mut T) -> Option<&mut Self>
where T: Pod,

Creates a mutable POD reference with the inverse of map_mut()
Source§

fn ref_from_slice<T>(p: &[T]) -> Option<&Self>
where T: Pod,

Creates a POD reference with the inverse of merge()
Source§

fn ref_from_slice_mut<T>(p: &mut [T]) -> Option<&mut Self>
where T: Pod,

Creates a mutable POD reference with the inverse of merge_mut()
Source§

fn as_bytes(&self) -> &[u8]

Borrows the POD as a byte slice
Source§

fn as_bytes_mut(&mut self) -> &mut [u8]

Borrows the POD as a mutable byte slice
Source§

fn from_bytes(p: &[u8]) -> Option<Self>

Safely creates a POD value from a potentially unaligned slice Read more
Source§

fn ref_from_bytes(p: &[u8]) -> Option<&Self>

Borrows a new instance of the POD from a byte slice Read more
Source§

fn ref_from_bytes_mut(p: &mut [u8]) -> Option<&mut Self>

Borrows a mutable instance of the POD from a mutable byte slice Read more
Source§

fn from_byte_slice(p: Box<[u8]>) -> Result<Box<Self>, Box<[u8]>>

Converts a boxed slice to a boxed instance of the POD type Read more
Source§

fn from_byte_vec(p: Vec<u8>) -> Result<Box<Self>, Vec<u8>>

Converts a byte vector to a boxed instance of the POD type Read more
Source§

fn into_byte_slice(self: Box<Self>) -> Box<[u8]>

Converts a boxed POD to a boxed slice
Source§

fn into_byte_vec(self: Box<Self>) -> Vec<u8>

Converts a boxed POD to a byte vector
Source§

fn as_aligned_mut<T>(&mut self) -> Option<&mut T>
where T: Pod + Aligned<Unaligned = Self>, Self: Copy + Unaligned,

Safely borrows the aligned value mutably Read more
Source§

impl<B, T: EndianConvert, A: Copy> Copy for EndianPrimitive<B, T, A>

Source§

impl<A, B: ByteOrder, T: EndianConvert + Eq> Eq for EndianPrimitive<B, T, A>

Source§

impl<B, T: EndianConvert, A: Unaligned> Packed for EndianPrimitive<B, T, A>

Source§

impl<B, T: EndianConvert, A: Unaligned> Unaligned for EndianPrimitive<B, T, A>

Auto Trait Implementations§

§

impl<B, T, Alignment> Freeze for EndianPrimitive<B, T, Alignment>
where <T as Aligned>::Unaligned: Freeze, Alignment: Freeze,

§

impl<B, T, Alignment> RefUnwindSafe for EndianPrimitive<B, T, Alignment>

§

impl<B, T, Alignment = ()> !Send for EndianPrimitive<B, T, Alignment>

§

impl<B, T, Alignment = ()> !Sync for EndianPrimitive<B, T, Alignment>

§

impl<B, T, Alignment> Unpin for EndianPrimitive<B, T, Alignment>
where <T as Aligned>::Unaligned: Unpin, Alignment: Unpin,

§

impl<B, T, Alignment> UnwindSafe for EndianPrimitive<B, T, Alignment>
where <T as Aligned>::Unaligned: UnwindSafe, Alignment: UnwindSafe, B: RefUnwindSafe,

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