[−][src]Struct zerocopy::byteorder::U16  
A 16-bit unsigned integer
stored in O byte order.
U16 is like the native u16 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 U16 can be constructed using
the new method, and its contained value can be obtained as a native
u16 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 U16
has endianness O and that, b) the layout of u16 has
the platform's native endianness.
U16 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.
Methods
impl<O: ByteOrder> U16<O>[src]
pub const ZERO: U16<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 const MAX_VALUE: U16<O>[src]
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.
pub fn new(n: u16) -> U16<O>[src]
Constructs a new value, possibly performing an endianness swap
to guarantee that the returned value has endianness O.
pub fn get(self) -> u16[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: u16)[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> FromBytes for U16<O> where
    PhantomData<O>: FromBytes, [src]
PhantomData<O>: FromBytes,
fn only_derive_is_allowed_to_implement_this_trait() where
    Self: Sized, [src]
Self: Sized,
impl<O: ByteOrder> AsBytes for U16<O>[src]
fn only_derive_is_allowed_to_implement_this_trait() where
    Self: Sized, [src]
Self: Sized,
fn as_bytes(&self) -> &[u8][src]
Get the bytes of this value. Read more
fn as_bytes_mut(&mut self) -> &mut [u8] where
    Self: FromBytes, [src]
Self: FromBytes,
Get the bytes of this value mutably. Read more
impl<O: ByteOrder> Unaligned for U16<O> where
    PhantomData<O>: Unaligned, [src]
PhantomData<O>: Unaligned,
fn only_derive_is_allowed_to_implement_this_trait() where
    Self: Sized, [src]
Self: Sized,
impl<O: ByteOrder> Display for U16<O>[src]
impl<O: ByteOrder> Debug for U16<O>[src]
impl<O: PartialEq + ByteOrder> PartialEq<U16<O>> for U16<O>[src]
impl<O: ByteOrder> PartialEq<U16<O>> for [u8; 2][src]
fn eq(&self, other: &U16<O>) -> bool[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool1.0.0[src]
This method tests for !=.
impl<O: ByteOrder> PartialEq<[u8; 2]> for U16<O>[src]
fn eq(&self, other: &[u8; 2]) -> bool[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool1.0.0[src]
This method tests for !=.
impl<O: Eq + ByteOrder> Eq for U16<O>[src]
impl<O: Copy + ByteOrder> Copy for U16<O>[src]
impl<O: ByteOrder> AsRef<[u8; 2]> for U16<O>[src]
impl<O: ByteOrder> AsMut<[u8; 2]> for U16<O>[src]
impl<O: ByteOrder> From<U16<O>> for [u8; 2][src]
impl<O: ByteOrder> From<[u8; 2]> for U16<O>[src]
impl<O: ByteOrder> Octal for U16<O>[src]
impl<O: ByteOrder> Binary for U16<O>[src]
impl<O: ByteOrder> LowerHex for U16<O>[src]
impl<O: ByteOrder> UpperHex for U16<O>[src]
impl<O: Clone + ByteOrder> Clone for U16<O>[src]
fn clone(&self) -> U16<O>[src]
fn clone_from(&mut self, source: &Self)1.0.0[src]
Performs copy-assignment from source. Read more
impl<O: Default + ByteOrder> Default for U16<O>[src]
Auto Trait Implementations
impl<O> Unpin for U16<O> where
    O: Unpin, 
O: Unpin,
impl<O> Send for U16<O> where
    O: Send, 
O: Send,
impl<O> Sync for U16<O> where
    O: Sync, 
O: Sync,
impl<O> UnwindSafe for U16<O> where
    O: UnwindSafe, 
O: UnwindSafe,
impl<O> RefUnwindSafe for U16<O> where
    O: RefUnwindSafe, 
O: RefUnwindSafe,
Blanket Implementations
impl<T, U> TryFrom<U> for T where
    U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> Into<U> for T where
    U: From<T>, [src]
U: From<T>,
impl<T> From<T> for T[src]
impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, [src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]
impl<T> Borrow<T> for T where
    T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
    T: ?Sized, [src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T[src]
impl<T> Any for T where
    T: 'static + ?Sized, [src]
T: 'static + ?Sized,
impl<T> ToOwned for T where
    T: Clone, [src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T[src]
fn clone_into(&self, target: &mut T)[src]
impl<T> ToString for T where
    T: Display + ?Sized, [src]
T: Display + ?Sized,