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