pub struct UnalignedI16(/* private fields */);Expand description
A i16 that has an alignment requirement of 1 byte, i.e. is unaligned
This is useful in packed structures and slices of data contained in variable-length arrays in VPP messages.
§Layout
UnalignedI16 is guaranteed to have the same layout and bit validity as i16.
They are also guaranteed to have the same size.
Implementations§
Source§impl UnalignedI16
impl UnalignedI16
Sourcepub const fn new(value: i16) -> Self
pub const fn new(value: i16) -> Self
Creates a i16 that has an alignment requirement of 1 byte, i.e. is unaligned.
Sourcepub const fn swap_bytes(self) -> Self
pub const fn swap_bytes(self) -> Self
Reverses the byte order of the integer.
§Examples
let n = UnalignedI16::new(0x1234i16);
let m = n.swap_bytes();
assert_eq!(m, 0x3412);Sourcepub const fn to_be(self) -> Self
pub const fn to_be(self) -> Self
Converts self to big endian from the target’s endianness.
On big endian this is a no-op. On little endian the bytes are swapped.
§Examples
let n = UnalignedI16::new(0x1Ai16);
if cfg!(target_endian = "big") {
assert_eq!(n.to_be(), n)
} else {
assert_eq!(n.to_be(), n.swap_bytes())
}Sourcepub const fn from_be(x: Self) -> Self
pub const fn from_be(x: Self) -> Self
Converts an integer from big endian to the target’s endianness.
On big endian this is a no-op. On little endian the bytes are swapped.
§Examples
let n = UnalignedI16::new(0x1Ai16);
if cfg!(target_endian = "big") {
assert_eq!(UnalignedI16::from_be(n), n)
} else {
assert_eq!(UnalignedI16::from_be(n), n.swap_bytes())
}Trait Implementations§
Source§impl Add<i16> for UnalignedI16
impl Add<i16> for UnalignedI16
Source§impl Add for UnalignedI16
impl Add for UnalignedI16
Source§impl Clone for UnalignedI16
impl Clone for UnalignedI16
Source§fn clone(&self) -> UnalignedI16
fn clone(&self) -> UnalignedI16
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for UnalignedI16
impl Debug for UnalignedI16
Source§impl Display for UnalignedI16
impl Display for UnalignedI16
Source§impl Div<i16> for UnalignedI16
impl Div<i16> for UnalignedI16
Source§impl Div for UnalignedI16
impl Div for UnalignedI16
Source§impl From<UnalignedI16> for i16
impl From<UnalignedI16> for i16
Source§fn from(value: UnalignedI16) -> Self
fn from(value: UnalignedI16) -> Self
Converts to this type from the input type.
Source§impl From<i16> for UnalignedI16
impl From<i16> for UnalignedI16
Source§impl FromStr for UnalignedI16
impl FromStr for UnalignedI16
Source§impl Hash for UnalignedI16
impl Hash for UnalignedI16
Source§impl Mul<i16> for UnalignedI16
impl Mul<i16> for UnalignedI16
Source§impl Mul for UnalignedI16
impl Mul for UnalignedI16
Source§impl Ord for UnalignedI16
impl Ord for UnalignedI16
Source§fn cmp(&self, other: &UnalignedI16) -> Ordering
fn cmp(&self, other: &UnalignedI16) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl PartialEq<i16> for UnalignedI16
impl PartialEq<i16> for UnalignedI16
Source§impl PartialEq for UnalignedI16
impl PartialEq for UnalignedI16
Source§impl PartialOrd<i16> for UnalignedI16
impl PartialOrd<i16> for UnalignedI16
Source§impl PartialOrd for UnalignedI16
impl PartialOrd for UnalignedI16
Source§impl Sub<i16> for UnalignedI16
impl Sub<i16> for UnalignedI16
Source§impl Sub for UnalignedI16
impl Sub for UnalignedI16
impl Copy for UnalignedI16
impl Eq for UnalignedI16
impl StructuralPartialEq for UnalignedI16
Auto Trait Implementations§
impl Freeze for UnalignedI16
impl RefUnwindSafe for UnalignedI16
impl Send for UnalignedI16
impl Sync for UnalignedI16
impl Unpin for UnalignedI16
impl UnsafeUnpin for UnalignedI16
impl UnwindSafe for UnalignedI16
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more