pub struct UnalignedF64(/* private fields */);Expand description
A f64 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
UnalignedF64 is guaranteed to have the same layout and bit validity as f64.
They are also guaranteed to have the same size.
Implementations§
Source§impl UnalignedF64
impl UnalignedF64
Sourcepub const fn new(value: f64) -> Self
pub const fn new(value: f64) -> Self
Creates a f64 that has an alignment requirement of 1 byte, i.e. is unaligned.
Sourcepub fn swap_bytes(self) -> Self
pub fn swap_bytes(self) -> Self
Reverses the byte order of the float.
§Examples
let n = UnalignedF64::new(1.0f64);
let m = n.swap_bytes();
// The result depends on the endianness of the targetSourcepub fn to_be(self) -> Self
pub 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 = UnalignedF64::new(1.0f64);
if cfg!(target_endian = "big") {
assert_eq!(n.to_be(), n)
} else {
assert_eq!(n.to_be(), n.swap_bytes())
}Sourcepub fn from_be(x: Self) -> Self
pub fn from_be(x: Self) -> Self
Converts a float 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 = UnalignedF64::new(1.0f64);
if cfg!(target_endian = "big") {
assert_eq!(UnalignedF64::from_be(n), n)
} else {
assert_eq!(UnalignedF64::from_be(n), n.swap_bytes())
}Trait Implementations§
Source§impl Add<f64> for UnalignedF64
impl Add<f64> for UnalignedF64
Source§impl Add for UnalignedF64
impl Add for UnalignedF64
Source§impl Clone for UnalignedF64
impl Clone for UnalignedF64
Source§fn clone(&self) -> UnalignedF64
fn clone(&self) -> UnalignedF64
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 UnalignedF64
impl Debug for UnalignedF64
Source§impl Display for UnalignedF64
impl Display for UnalignedF64
Source§impl Div<f64> for UnalignedF64
impl Div<f64> for UnalignedF64
Source§impl Div for UnalignedF64
impl Div for UnalignedF64
Source§impl From<UnalignedF64> for f64
impl From<UnalignedF64> for f64
Source§fn from(value: UnalignedF64) -> Self
fn from(value: UnalignedF64) -> Self
Converts to this type from the input type.
Source§impl From<f64> for UnalignedF64
impl From<f64> for UnalignedF64
Source§impl FromStr for UnalignedF64
impl FromStr for UnalignedF64
Source§impl Mul<f64> for UnalignedF64
impl Mul<f64> for UnalignedF64
Source§impl Mul for UnalignedF64
impl Mul for UnalignedF64
Source§impl PartialEq<f64> for UnalignedF64
impl PartialEq<f64> for UnalignedF64
Source§impl PartialEq for UnalignedF64
impl PartialEq for UnalignedF64
Source§impl PartialOrd<f64> for UnalignedF64
impl PartialOrd<f64> for UnalignedF64
Source§impl PartialOrd for UnalignedF64
impl PartialOrd for UnalignedF64
Source§impl Sub<f64> for UnalignedF64
impl Sub<f64> for UnalignedF64
Source§impl Sub for UnalignedF64
impl Sub for UnalignedF64
impl Copy for UnalignedF64
impl StructuralPartialEq for UnalignedF64
Auto Trait Implementations§
impl Freeze for UnalignedF64
impl RefUnwindSafe for UnalignedF64
impl Send for UnalignedF64
impl Sync for UnalignedF64
impl Unpin for UnalignedF64
impl UnsafeUnpin for UnalignedF64
impl UnwindSafe for UnalignedF64
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