Struct zerocopy::byteorder::I16 [−][src]
#[repr(transparent)]pub struct I16<O: ByteOrder>(_, _);
A 16-bit signed integer
stored in O
byte order.
I16
is like the native i16
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 I16
can be constructed using
the new
method, and its contained value can be obtained as a native
i16
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 I16
has endianness O
and that, b) the layout of i16
has
the platform’s native endianness.
I16
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
impl<O: ByteOrder> I16<O>
[src]
impl<O: ByteOrder> I16<O>
[src]pub const ZERO: I16<O>
[src]
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.
pub fn new(n: i16) -> I16<O>
[src]
Constructs a new value, possibly performing an endianness swap
to guarantee that the returned value has endianness O
.
pub fn get(self) -> i16
[src]
Returns the value as a primitive type, possibly performing an endianness swap to guarantee that the return value has the endianness of the native platform.
pub fn set(&mut self, n: i16)
[src]
Updates the value in place as a primitive type, possibly
performing an endianness swap to guarantee that the stored value
has the endianness O
.
Trait Implementations
impl<O: ByteOrder> AsBytes for I16<O>
[src]
impl<O: ByteOrder> AsBytes for I16<O>
[src]fn only_derive_is_allowed_to_implement_this_trait() where
Self: Sized,
[src]
Self: Sized,
fn as_bytes(&self) -> &[u8]
[src]
fn as_bytes_mut(&mut self) -> &mut [u8] where
Self: FromBytes,
[src]
Self: FromBytes,
impl<O: Clone + ByteOrder> Clone for I16<O>
[src]
impl<O: Clone + ByteOrder> Clone for I16<O>
[src]fn clone(&self) -> I16<O>
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<O: ByteOrder> FromBytes for I16<O> where
PhantomData<O>: FromBytes,
[src]
impl<O: ByteOrder> FromBytes for I16<O> where
PhantomData<O>: FromBytes,
[src]fn only_derive_is_allowed_to_implement_this_trait() where
Self: Sized,
[src]
Self: Sized,
impl<O: ByteOrder> StructuralEq for I16<O>
[src]
impl<O: ByteOrder> StructuralEq for I16<O>
[src]impl<O: ByteOrder> StructuralPartialEq for I16<O>
[src]
impl<O: ByteOrder> StructuralPartialEq for I16<O>
[src]impl<O: ByteOrder, P: ByteOrder> TryFrom<I128<P>> for I16<O>
[src]
impl<O: ByteOrder, P: ByteOrder> TryFrom<I128<P>> for I16<O>
[src]type Error = TryFromIntError
The type returned in the event of a conversion error.
fn try_from(x: I128<P>) -> Result<I16<O>, TryFromIntError>
[src]
impl<O: ByteOrder, P: ByteOrder> TryFrom<I32<P>> for I16<O>
[src]
impl<O: ByteOrder, P: ByteOrder> TryFrom<I32<P>> for I16<O>
[src]type Error = TryFromIntError
The type returned in the event of a conversion error.
fn try_from(x: I32<P>) -> Result<I16<O>, TryFromIntError>
[src]
impl<O: ByteOrder, P: ByteOrder> TryFrom<I64<P>> for I16<O>
[src]
impl<O: ByteOrder, P: ByteOrder> TryFrom<I64<P>> for I16<O>
[src]type Error = TryFromIntError
The type returned in the event of a conversion error.
fn try_from(x: I64<P>) -> Result<I16<O>, TryFromIntError>
[src]
impl<O: ByteOrder> TryFrom<i128> for I16<O>
[src]
impl<O: ByteOrder> TryFrom<i128> for I16<O>
[src]type Error = TryFromIntError
The type returned in the event of a conversion error.
fn try_from(x: i128) -> Result<I16<O>, TryFromIntError>
[src]
impl<O: ByteOrder> TryFrom<i32> for I16<O>
[src]
impl<O: ByteOrder> TryFrom<i32> for I16<O>
[src]type Error = TryFromIntError
The type returned in the event of a conversion error.
fn try_from(x: i32) -> Result<I16<O>, TryFromIntError>
[src]
impl<O: ByteOrder> TryFrom<i64> for I16<O>
[src]
impl<O: ByteOrder> TryFrom<i64> for I16<O>
[src]type Error = TryFromIntError
The type returned in the event of a conversion error.
fn try_from(x: i64) -> Result<I16<O>, TryFromIntError>
[src]
impl<O: ByteOrder> TryFrom<isize> for I16<O>
[src]
impl<O: ByteOrder> TryFrom<isize> for I16<O>
[src]type Error = TryFromIntError
The type returned in the event of a conversion error.
fn try_from(x: isize) -> Result<I16<O>, TryFromIntError>
[src]
impl<O: ByteOrder> Unaligned for I16<O> where
PhantomData<O>: Unaligned,
[src]
impl<O: ByteOrder> Unaligned for I16<O> where
PhantomData<O>: Unaligned,
[src]fn only_derive_is_allowed_to_implement_this_trait() where
Self: Sized,
[src]
Self: Sized,