Crate rend

source · []
Expand description

rend

rend is a library that provides endian-aware primitives for Rust.

It’s similar in design to simple_endian, but has support for more builtin types such as atomics and nonzero integers. It also has support for const functions since it does not rely on traits.

rend does not provide endian-aware types for types that are inherently endian-agnostic, such as bool and u8. It does not provide endian-aware types for types that have an architecture-dependent size, such as isize and usize. It’s also not extensible to custom types.

rend is intended to be used to build portable types that can be shared between different architectures, especially with zero-copy deserialization.

Features

  • std: Enables standard library support (enabled by default)
  • validation: Enables validation support through bytecheck

Example:

use rend::*;

let little_int = i32_le::new(0x12345678);
// Internal representation is little-endian
assert_eq!(
    [0x78, 0x56, 0x34, 0x12],
    unsafe { ::core::mem::transmute::<_, [u8; 4]>(little_int) }
);

// Can also be made with `.into()`
let little_int: i32_le = 0x12345678.into();
// Still formats correctly
assert_eq!("305419896", format!("{}", little_int));
assert_eq!("0x12345678", format!("0x{:x}", little_int));

let big_int = i32_be::new(0x12345678);
// Internal representation is big-endian
assert_eq!(
    [0x12, 0x34, 0x56, 0x78],
    unsafe { ::core::mem::transmute::<_, [u8; 4]>(big_int) }
);

// Can also be made with `.into()`
let big_int: i32_be = 0x12345678.into();
// Still formats correctly
assert_eq!("305419896", format!("{}", big_int));
assert_eq!("0x12345678", format!("0x{:x}", big_int));

Structs

A wrapper for little-endian types.
A wrapper for big-endian types.
A wrapper for native-endian types.

Type Definitions

Alias for BigEndian
Alias for LittleEndian
Alias for NativeEndian
Alias for BigEndian
Alias for LittleEndian
Alias for NativeEndian
Alias for BigEndian
Alias for LittleEndian
Alias for NativeEndian
Alias for BigEndian
Alias for LittleEndian
Alias for NativeEndian
Alias for BigEndian
Alias for LittleEndian
Alias for NativeEndian
Alias for BigEndian
Alias for LittleEndian
Alias for NativeEndian
Alias for BigEndian
Alias for LittleEndian
Alias for NativeEndian
Alias for BigEndian
Alias for LittleEndian
Alias for NativeEndian
Alias for BigEndian
Alias for LittleEndian
Alias for NativeEndian
Alias for BigEndian
Alias for LittleEndian
Alias for NativeEndian
Alias for BigEndian
Alias for LittleEndian
Alias for NativeEndian
Alias for BigEndian
Alias for LittleEndian
Alias for NativeEndian
Alias for BigEndian
Alias for LittleEndian
Alias for NativeEndian
Alias for BigEndian
Alias for LittleEndian
Alias for NativeEndian
Alias for BigEndian
Alias for LittleEndian
Alias for NativeEndian
Alias for BigEndian
Alias for LittleEndian
Alias for NativeEndian
Alias for BigEndian
Alias for LittleEndian
Alias for NativeEndian
Alias for BigEndian
Alias for LittleEndian
Alias for NativeEndian
Alias for BigEndian
Alias for LittleEndian
Alias for NativeEndian
Alias for BigEndian
Alias for LittleEndian
Alias for NativeEndian
Alias for BigEndian
Alias for LittleEndian
Alias for NativeEndian
Alias for BigEndian
Alias for LittleEndian
Alias for NativeEndian
Alias for BigEndian
Alias for LittleEndian
Alias for NativeEndian
Alias for BigEndian
Alias for LittleEndian
Alias for NativeEndian
Alias for BigEndian
Alias for LittleEndian
Alias for NativeEndian