pub struct UnalignedI32(/* private fields */);Expand description
A i32 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
UnalignedI32 is guaranteed to have the same layout and bit validity as i32.
They are also guaranteed to have the same size.
Implementations§
Source§impl UnalignedI32
impl UnalignedI32
Sourcepub const fn new(value: i32) -> Self
pub const fn new(value: i32) -> Self
Creates a i32 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 = UnalignedI32::new(0x12345678i32);
let m = n.swap_bytes();
assert_eq!(m, 0x78563412);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 = UnalignedI32::new(0x1Ai32);
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 = UnalignedI32::new(0x1Ai32);
if cfg!(target_endian = "big") {
assert_eq!(UnalignedI32::from_be(n), n)
} else {
assert_eq!(UnalignedI32::from_be(n), n.swap_bytes())
}Trait Implementations§
Source§impl Add<i32> for UnalignedI32
impl Add<i32> for UnalignedI32
Source§impl Add for UnalignedI32
impl Add for UnalignedI32
Source§impl Clone for UnalignedI32
impl Clone for UnalignedI32
Source§fn clone(&self) -> UnalignedI32
fn clone(&self) -> UnalignedI32
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 UnalignedI32
impl Debug for UnalignedI32
Source§impl Display for UnalignedI32
impl Display for UnalignedI32
Source§impl Div<i32> for UnalignedI32
impl Div<i32> for UnalignedI32
Source§impl Div for UnalignedI32
impl Div for UnalignedI32
Source§impl From<UnalignedI32> for i32
impl From<UnalignedI32> for i32
Source§fn from(value: UnalignedI32) -> Self
fn from(value: UnalignedI32) -> Self
Converts to this type from the input type.
Source§impl From<i32> for UnalignedI32
impl From<i32> for UnalignedI32
Source§impl FromStr for UnalignedI32
impl FromStr for UnalignedI32
Source§impl Hash for UnalignedI32
impl Hash for UnalignedI32
Source§impl Mul<i32> for UnalignedI32
impl Mul<i32> for UnalignedI32
Source§impl Mul for UnalignedI32
impl Mul for UnalignedI32
Source§impl Ord for UnalignedI32
impl Ord for UnalignedI32
Source§fn cmp(&self, other: &UnalignedI32) -> Ordering
fn cmp(&self, other: &UnalignedI32) -> 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<i32> for UnalignedI32
impl PartialEq<i32> for UnalignedI32
Source§impl PartialEq for UnalignedI32
impl PartialEq for UnalignedI32
Source§impl PartialOrd<i32> for UnalignedI32
impl PartialOrd<i32> for UnalignedI32
Source§impl PartialOrd for UnalignedI32
impl PartialOrd for UnalignedI32
Source§impl Sub<i32> for UnalignedI32
impl Sub<i32> for UnalignedI32
Source§impl Sub for UnalignedI32
impl Sub for UnalignedI32
impl Copy for UnalignedI32
impl Eq for UnalignedI32
impl StructuralPartialEq for UnalignedI32
Auto Trait Implementations§
impl Freeze for UnalignedI32
impl RefUnwindSafe for UnalignedI32
impl Send for UnalignedI32
impl Sync for UnalignedI32
impl Unpin for UnalignedI32
impl UnsafeUnpin for UnalignedI32
impl UnwindSafe for UnalignedI32
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