pub struct I32<O>(_, _)
where
O: ByteOrder;Expand description
A 32-bit signed integer
stored in O byte order.
I32 is like the native i32 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.
An I32 can be constructed using
the new method, and its contained value can be obtained as a native
i32 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 I32
has endianness O and that, b) the layout of i32 has
the platform’s native endianness.
I32 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> I32<O>where
O: ByteOrder,
impl<O> I32<O>where O: ByteOrder,
sourcepub const ZERO: I32<O> = I32([0u8; 4], PhantomData)
pub const ZERO: I32<O> = I32([0u8; 4], PhantomData)
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 fn new(n: i32) -> I32<O>
pub fn new(n: i32) -> I32<O>
Constructs a new value, possibly performing an endianness swap
to guarantee that the returned value has endianness O.
Trait Implementations§
source§impl<O> AsBytes for I32<O>where
O: ByteOrder,
impl<O> AsBytes for I32<O>where O: ByteOrder,
source§fn as_bytes_mut(&mut self) -> &mut [u8] ⓘwhere
Self: FromBytes,
fn as_bytes_mut(&mut self) -> &mut [u8] ⓘwhere Self: FromBytes,
source§fn write_to_prefix<B>(&self, bytes: B) -> Option<()>where
B: ByteSliceMut,
fn write_to_prefix<B>(&self, bytes: B) -> Option<()>where B: ByteSliceMut,
source§fn write_to_suffix<B>(&self, bytes: B) -> Option<()>where
B: ByteSliceMut,
fn write_to_suffix<B>(&self, bytes: B) -> Option<()>where B: ByteSliceMut,
source§impl<O> FromBytes for I32<O>where
O: ByteOrder,
PhantomData<O>: FromBytes,
impl<O> FromBytes for I32<O>where O: ByteOrder, PhantomData<O>: FromBytes,
source§fn new_zeroed() -> Selfwhere
Self: Sized,
fn new_zeroed() -> Selfwhere Self: Sized,
Self from zeroed bytes.