Expand description
§rend
rend provides cross-platform, endian-aware primitives for Rust.
rend does not provide cross-platform alternatives for types that are
inherently cross-platform, such as bool and u8. It also does not provide
cross-platform alternatives for types that have an architecture-dependent
size, such as isize and usize. rend does not support custom types.
rend is intended to be used to build portable types that can be shared between different architectures.
§Features
bytecheck: Enables support for validating types usingbytecheck.
§Crates
zerocopy-0_8
§Example:
use core::mem::transmute;
use rend::*;
let little_int = i32_le::from_native(0x12345678);
// Internal representation is little-endian
assert_eq!(
[0x78, 0x56, 0x34, 0x12],
unsafe { 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::from_native(0x12345678);
// Internal representation is big-endian
assert_eq!(
[0x12, 0x34, 0x56, 0x78],
unsafe { 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));Modules§
- unaligned
- Cross-platform primitives with unaligned representations.
Structs§
- Atomic
I16_ be - A big-endian
AtomicI16with a guaranteed size and alignment of2. - Atomic
I16_ le - A little-endian
AtomicI16with a guaranteed size and alignment of2. - Atomic
I32_ be - A big-endian
AtomicI32with a guaranteed size and alignment of4. - Atomic
I32_ le - A little-endian
AtomicI32with a guaranteed size and alignment of4. - Atomic
I64_ be - A big-endian
AtomicI64with a guaranteed size and alignment of8. - Atomic
I64_ le - A little-endian
AtomicI64with a guaranteed size and alignment of8. - Atomic
U16_ be - A big-endian
AtomicU16with a guaranteed size and alignment of2. - Atomic
U16_ le - A little-endian
AtomicU16with a guaranteed size and alignment of2. - Atomic
U32_ be - A big-endian
AtomicU32with a guaranteed size and alignment of4. - Atomic
U32_ le - A little-endian
AtomicU32with a guaranteed size and alignment of4. - Atomic
U64_ be - A big-endian
AtomicU64with a guaranteed size and alignment of8. - Atomic
U64_ le - A little-endian
AtomicU64with a guaranteed size and alignment of8. - NonZero
I16_ be - A big-endian
NonZeroI16with a guaranteed size and alignment of2. - NonZero
I16_ le - A little-endian
NonZeroI16with a guaranteed size and alignment of2. - NonZero
I32_ be - A big-endian
NonZeroI32with a guaranteed size and alignment of4. - NonZero
I32_ le - A little-endian
NonZeroI32with a guaranteed size and alignment of4. - NonZero
I64_ be - A big-endian
NonZeroI64with a guaranteed size and alignment of8. - NonZero
I64_ le - A little-endian
NonZeroI64with a guaranteed size and alignment of8. - NonZero
I128_ be - A big-endian
NonZeroI128with a guaranteed size and alignment of16. - NonZero
I128_ le - A little-endian
NonZeroI128with a guaranteed size and alignment of16. - NonZero
U16_ be - A big-endian
NonZeroU16with a guaranteed size and alignment of2. - NonZero
U16_ le - A little-endian
NonZeroU16with a guaranteed size and alignment of2. - NonZero
U32_ be - A big-endian
NonZeroU32with a guaranteed size and alignment of4. - NonZero
U32_ le - A little-endian
NonZeroU32with a guaranteed size and alignment of4. - NonZero
U64_ be - A big-endian
NonZeroU64with a guaranteed size and alignment of8. - NonZero
U64_ le - A little-endian
NonZeroU64with a guaranteed size and alignment of8. - NonZero
U128_ be - A big-endian
NonZeroU128with a guaranteed size and alignment of16. - NonZero
U128_ le - A little-endian
NonZeroU128with a guaranteed size and alignment of16. - char_be
- A big-endian
u32with a guaranteed size and alignment of4. - char_le
- A little-endian
u32with a guaranteed size and alignment of4. - f32_be
- A big-endian
f32with a guaranteed size and alignment of4. - f32_le
- A little-endian
f32with a guaranteed size and alignment of4. - f64_be
- A big-endian
f64with a guaranteed size and alignment of8. - f64_le
- A little-endian
f64with a guaranteed size and alignment of8. - i16_be
- A big-endian
i16with a guaranteed size and alignment of2. - i16_le
- A little-endian
i16with a guaranteed size and alignment of2. - i32_be
- A big-endian
i32with a guaranteed size and alignment of4. - i32_le
- A little-endian
i32with a guaranteed size and alignment of4. - i64_be
- A big-endian
i64with a guaranteed size and alignment of8. - i64_le
- A little-endian
i64with a guaranteed size and alignment of8. - i128_be
- A big-endian
i128with a guaranteed size and alignment of16. - i128_le
- A little-endian
i128with a guaranteed size and alignment of16. - u16_be
- A big-endian
u16with a guaranteed size and alignment of2. - u16_le
- A little-endian
u16with a guaranteed size and alignment of2. - u32_be
- A big-endian
u32with a guaranteed size and alignment of4. - u32_le
- A little-endian
u32with a guaranteed size and alignment of4. - u64_be
- A big-endian
u64with a guaranteed size and alignment of8. - u64_le
- A little-endian
u64with a guaranteed size and alignment of8. - u128_be
- A big-endian
u128with a guaranteed size and alignment of16. - u128_le
- A little-endian
u128with a guaranteed size and alignment of16.