Module endian

Source
Expand description

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

Each endian type is guarnteed to have the same size and alignment as a regular unsigned primiive 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§

Be16
An unsigned integer type of with an explicit endianness.
Be32
An unsigned integer type of with an explicit endianness.
Be64
An unsigned integer type of with an explicit endianness.
BeSize
An unsigned integer type of with an explicit endianness.
Le16
An unsigned integer type of with an explicit endianness.
Le32
An unsigned integer type of with an explicit endianness.
Le64
An unsigned integer type of with an explicit endianness.
LeSize
An unsigned integer type of with an explicit endianness.