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