pub struct U32<O: ByteOrder>(/* private fields */);
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§
source§impl<O: ByteOrder> U32<O>
impl<O: ByteOrder> U32<O>
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
.