#[repr(transparent)]pub struct U32<O>(_, _)
where
O: ByteOrder;
Expand description
A 32-bit unsigned integer
stored in O
byte order.
U32
is like the native u32
type with
two major differences: First, it has no alignment requirement (its alignment is 1).
Second, the endianness of its memory layout is given by the type parameter O
.
A U32
can be constructed using
the new
method, and its contained value can be obtained as a native
u32
using the get
method, or updated in place with
the set
method. In all cases, if the endianness O
is not the same as the
endianness of the current platform, an endianness swap will be performed in
order to uphold the invariants that a) the layout of U32
has endianness O
and that, b) the layout of u32
has
the platform’s native endianness.
U32
implements FromBytes
, AsBytes
, and Unaligned
,
making it useful for parsing and serialization. See the module documentation for an
example of how it can be used for parsing UDP packets.
Implementations
sourceimpl<O> U32<O> where
O: ByteOrder,
impl<O> U32<O> where
O: ByteOrder,
sourcepub const ZERO: U32<O>
pub const ZERO: U32<O>
The value zero.
This constant should be preferred to constructing a new value
using new
, as new
may perform an endianness swap depending
on the endianness and platform.
sourcepub const MAX_VALUE: U32<O>
pub const MAX_VALUE: U32<O>
The maximum value.
This constant should be preferred to constructing a new value using
new
, as new
may perform an endianness swap depending on the
endianness O
and the endianness of the platform.
sourcepub fn new(n: u32) -> U32<O>
pub fn new(n: u32) -> U32<O>
Constructs a new value, possibly performing an endianness swap
to guarantee that the returned value has endianness O
.
Trait Implementations
sourceimpl<O> AsBytes for U32<O> where
O: ByteOrder,
impl<O> AsBytes for U32<O> where
O: ByteOrder,
pub fn only_derive_is_allowed_to_implement_this_trait() where
U32<O>: Sized,
sourcefn as_bytes(&self) -> &[u8]ⓘNotable traits for &'_ [u8]impl Read for &'_ [u8]impl Write for &'_ mut [u8]
fn as_bytes(&self) -> &[u8]ⓘNotable traits for &'_ [u8]impl Read for &'_ [u8]impl Write for &'_ mut [u8]
Gets the bytes of this value. Read more
sourcefn as_bytes_mut(&mut self) -> &mut [u8]ⓘNotable traits for &'_ [u8]impl Read for &'_ [u8]impl Write for &'_ mut [u8]
where
Self: FromBytes,
fn as_bytes_mut(&mut self) -> &mut [u8]ⓘNotable traits for &'_ [u8]impl Read for &'_ [u8]impl Write for &'_ mut [u8]
where
Self: FromBytes,
Gets the bytes of this value mutably. Read more
sourcefn write_to<B>(&self, bytes: B) -> Option<()> where
B: ByteSliceMut,
fn write_to<B>(&self, bytes: B) -> Option<()> where
B: ByteSliceMut,
Writes a copy of self
to bytes
. Read more
sourcefn write_to_prefix<B>(&self, bytes: B) -> Option<()> where
B: ByteSliceMut,
fn write_to_prefix<B>(&self, bytes: B) -> Option<()> where
B: ByteSliceMut,
Writes a copy of self
to the prefix of bytes
. Read more
sourcefn write_to_suffix<B>(&self, bytes: B) -> Option<()> where
B: ByteSliceMut,
fn write_to_suffix<B>(&self, bytes: B) -> Option<()> where
B: ByteSliceMut,
Writes a copy of self
to the suffix of bytes
. Read more
sourceimpl<O> FromBytes for U32<O> where
O: ByteOrder,
PhantomData<O>: FromBytes,
impl<O> FromBytes for U32<O> where
O: ByteOrder,
PhantomData<O>: FromBytes,
pub fn only_derive_is_allowed_to_implement_this_trait() where
U32<O>: Sized,
sourcefn read_from<B>(bytes: B) -> Option<Self> where
B: ByteSlice,
fn read_from<B>(bytes: B) -> Option<Self> where
B: ByteSlice,
Reads a copy of Self
from bytes
. Read more
sourcefn read_from_prefix<B>(bytes: B) -> Option<Self> where
B: ByteSlice,
fn read_from_prefix<B>(bytes: B) -> Option<Self> where
B: ByteSlice,
Reads a copy of Self
from the prefix of bytes
. Read more
sourcefn read_from_suffix<B>(bytes: B) -> Option<Self> where
B: ByteSlice,
fn read_from_suffix<B>(bytes: B) -> Option<Self> where
B: ByteSlice,
Reads a copy of Self
from the suffix of bytes
. Read more
sourcefn new_zeroed() -> Self
fn new_zeroed() -> Self
Creates an instance of Self
from zeroed bytes.
sourceimpl<O, P> TryFrom<U128<P>> for U32<O> where
O: ByteOrder,
P: ByteOrder,
impl<O, P> TryFrom<U128<P>> for U32<O> where
O: ByteOrder,
P: ByteOrder,
type Error = TryFromIntError
type Error = TryFromIntError
The type returned in the event of a conversion error.
sourceimpl<O, P> TryFrom<U32<P>> for U16<O> where
O: ByteOrder,
P: ByteOrder,
impl<O, P> TryFrom<U32<P>> for U16<O> where
O: ByteOrder,
P: ByteOrder,
type Error = TryFromIntError
type Error = TryFromIntError
The type returned in the event of a conversion error.
sourceimpl<O, P> TryFrom<U64<P>> for U32<O> where
O: ByteOrder,
P: ByteOrder,
impl<O, P> TryFrom<U64<P>> for U32<O> where
O: ByteOrder,
P: ByteOrder,
type Error = TryFromIntError
type Error = TryFromIntError
The type returned in the event of a conversion error.
sourceimpl<O> TryFrom<u128> for U32<O> where
O: ByteOrder,
impl<O> TryFrom<u128> for U32<O> where
O: ByteOrder,
type Error = TryFromIntError
type Error = TryFromIntError
The type returned in the event of a conversion error.
sourceimpl<O> TryFrom<u64> for U32<O> where
O: ByteOrder,
impl<O> TryFrom<u64> for U32<O> where
O: ByteOrder,
type Error = TryFromIntError
type Error = TryFromIntError
The type returned in the event of a conversion error.
sourceimpl<O> Unaligned for U32<O> where
O: ByteOrder,
PhantomData<O>: Unaligned,
impl<O> Unaligned for U32<O> where
O: ByteOrder,
PhantomData<O>: Unaligned,
pub fn only_derive_is_allowed_to_implement_this_trait() where
U32<O>: Sized,
impl<O> Copy for U32<O> where
O: Copy + ByteOrder,
impl<O> Eq for U32<O> where
O: Eq + ByteOrder,
impl<O> StructuralEq for U32<O> where
O: ByteOrder,
impl<O> StructuralPartialEq for U32<O> where
O: ByteOrder,
Auto Trait Implementations
impl<O> RefUnwindSafe for U32<O> where
O: RefUnwindSafe,
impl<O> Send for U32<O> where
O: Send,
impl<O> Sync for U32<O> where
O: Sync,
impl<O> Unpin for U32<O> where
O: Unpin,
impl<O> UnwindSafe for U32<O> where
O: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more