Module vm_memory::endian

source ·
Expand description

Explicit endian types useful for embedding in structs or reinterpreting data.

Each endian type is guaarnteed to have the same size and alignment as a regular unsigned primitive of the equal size.

§Examples

let b: Be32 = From::from(3);
let l: Le32 = From::from(3);

assert_eq!(b.to_native(), 3);
assert_eq!(l.to_native(), 3);
assert!(b == 3);
assert!(l == 3);

let b_trans: u32 = unsafe { std::mem::transmute(b) };
let l_trans: u32 = unsafe { std::mem::transmute(l) };

#[cfg(target_endian = "little")]
assert_eq!(l_trans, 3);
#[cfg(target_endian = "big")]
assert_eq!(b_trans, 3);

assert_ne!(b_trans, l_trans);

Structs§

  • An unsigned integer type of with an explicit endianness.
  • An unsigned integer type of with an explicit endianness.
  • An unsigned integer type of with an explicit endianness.
  • An unsigned integer type of with an explicit endianness.
  • An unsigned integer type of with an explicit endianness.
  • An unsigned integer type of with an explicit endianness.
  • An unsigned integer type of with an explicit endianness.
  • An unsigned integer type of with an explicit endianness.