Module data_model::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§

Structs§

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