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);

  // SAFETY: trivially safe
  let b_trans: u32 = unsafe { std::mem::transmute(b) };
  // SAFETY: trivially safe
  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);

Macros§

endian_type 🔒

Structs§

Be16
An integer type of with an explicit endianness.
Be32
An integer type of with an explicit endianness.
Be64
An integer type of with an explicit endianness.
BeSize
An integer type of with an explicit endianness.
Le16
An integer type of with an explicit endianness.
Le32
An integer type of with an explicit endianness.
Le64
An integer type of with an explicit endianness.
LeSize
An integer type of with an explicit endianness.
SBe16
An integer type of with an explicit endianness.
SBe32
An integer type of with an explicit endianness.
SBe64
An integer type of with an explicit endianness.
SBeSize
An integer type of with an explicit endianness.
SLe16
An integer type of with an explicit endianness.
SLe32
An integer type of with an explicit endianness.
SLe64
An integer type of with an explicit endianness.
SLeSize
An integer type of with an explicit endianness.