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 throughbytecheck
§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.
Traits§
- A type that has an associated cross-endian storage type.
Type Aliases§
- Alias for
BigEndian<AtomicI16>
. - Alias for
LittleEndian<AtomicI16>
. - Alias for
NativeEndian<AtomicI16>
. - Alias for
BigEndian<AtomicI32>
. - Alias for
LittleEndian<AtomicI32>
. - Alias for
NativeEndian<AtomicI32>
. - Alias for
BigEndian<AtomicI64>
. - Alias for
LittleEndian<AtomicI64>
. - Alias for
NativeEndian<AtomicI64>
. - Alias for
BigEndian<AtomicU16>
. - Alias for
LittleEndian<AtomicU16>
. - Alias for
NativeEndian<AtomicU16>
. - Alias for
BigEndian<AtomicU32>
. - Alias for
LittleEndian<AtomicU32>
. - Alias for
NativeEndian<AtomicU32>
. - Alias for
BigEndian<AtomicU64>
. - Alias for
LittleEndian<AtomicU64>
. - Alias for
NativeEndian<AtomicU64>
. - Alias for
BigEndian<NonZeroI16>
. - Alias for
LittleEndian<NonZeroI16>
. - Alias for
NativeEndian<NonZeroI16>
. - Alias for
BigEndian<NonZeroI32>
. - Alias for
LittleEndian<NonZeroI32>
. - Alias for
NativeEndian<NonZeroI32>
. - Alias for
BigEndian<NonZeroI64>
. - Alias for
LittleEndian<NonZeroI64>
. - Alias for
NativeEndian<NonZeroI64>
. - Alias for
BigEndian<NonZeroI128>
. - Alias for
LittleEndian<NonZeroI128>
. - Alias for
NativeEndian<NonZeroI128>
. - Alias for
BigEndian<NonZeroU16>
. - Alias for
LittleEndian<NonZeroU16>
. - Alias for
NativeEndian<NonZeroU16>
. - Alias for
BigEndian<NonZeroU32>
. - Alias for
LittleEndian<NonZeroU32>
. - Alias for
NativeEndian<NonZeroU32>
. - Alias for
BigEndian<NonZeroU64>
. - Alias for
LittleEndian<NonZeroU64>
. - Alias for
NativeEndian<NonZeroU64>
. - Alias for
BigEndian<NonZeroU128>
. - Alias for
LittleEndian<NonZeroU128>
. - Alias for
NativeEndian<NonZeroU128>
. - Alias for
BigEndian<char>
. - Alias for
LittleEndian<char>
. - Alias for
NativeEndian<char>
. - Alias for
BigEndian<f32>
. - Alias for
LittleEndian<f32>
. - Alias for
NativeEndian<f32>
. - Alias for
BigEndian<f64>
. - Alias for
LittleEndian<f64>
. - Alias for
NativeEndian<f64>
. - Alias for
BigEndian<i16>
. - Alias for
LittleEndian<i16>
. - Alias for
NativeEndian<i16>
. - Alias for
BigEndian<i32>
. - Alias for
LittleEndian<i32>
. - Alias for
NativeEndian<i32>
. - Alias for
BigEndian<i64>
. - Alias for
LittleEndian<i64>
. - Alias for
NativeEndian<i64>
. - Alias for
BigEndian<i128>
. - Alias for
LittleEndian<i128>
. - Alias for
NativeEndian<i128>
. - Alias for
BigEndian<u16>
. - Alias for
LittleEndian<u16>
. - Alias for
NativeEndian<u16>
. - Alias for
BigEndian<u32>
. - Alias for
LittleEndian<u32>
. - Alias for
NativeEndian<u32>
. - Alias for
BigEndian<u64>
. - Alias for
LittleEndian<u64>
. - Alias for
NativeEndian<u64>
. - Alias for
BigEndian<u128>
. - Alias for
LittleEndian<u128>
. - Alias for
NativeEndian<u128>
.