Expand description
§rend
rend is a library that provides cross-platform 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 types 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, especially with zero-copy deserialization.
§Features
bytecheck: Enables support for validating types usingbytecheck
§Example:
use rend::*;
let little_int = i32_le::from_native(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::from_native(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));Modules§
- Cross-platform primitives with unaligned representations.
Structs§
- A big-endian
AtomicI16with a guaranteed size and alignment of2. - A little-endian
AtomicI16with a guaranteed size and alignment of2. - A big-endian
AtomicI32with a guaranteed size and alignment of4. - A little-endian
AtomicI32with a guaranteed size and alignment of4. - A big-endian
AtomicI64with a guaranteed size and alignment of8. - A little-endian
AtomicI64with a guaranteed size and alignment of8. - A big-endian
AtomicU16with a guaranteed size and alignment of2. - A little-endian
AtomicU16with a guaranteed size and alignment of2. - A big-endian
AtomicU32with a guaranteed size and alignment of4. - A little-endian
AtomicU32with a guaranteed size and alignment of4. - A big-endian
AtomicU64with a guaranteed size and alignment of8. - A little-endian
AtomicU64with a guaranteed size and alignment of8. - A big-endian
NonZeroI16with a guaranteed size and alignment of2. - A little-endian
NonZeroI16with a guaranteed size and alignment of2. - A big-endian
NonZeroI32with a guaranteed size and alignment of4. - A little-endian
NonZeroI32with a guaranteed size and alignment of4. - A big-endian
NonZeroI64with a guaranteed size and alignment of8. - A little-endian
NonZeroI64with a guaranteed size and alignment of8. - A big-endian
NonZeroI128with a guaranteed size and alignment of16. - A little-endian
NonZeroI128with a guaranteed size and alignment of16. - A big-endian
NonZeroU16with a guaranteed size and alignment of2. - A little-endian
NonZeroU16with a guaranteed size and alignment of2. - A big-endian
NonZeroU32with a guaranteed size and alignment of4. - A little-endian
NonZeroU32with a guaranteed size and alignment of4. - A big-endian
NonZeroU64with a guaranteed size and alignment of8. - A little-endian
NonZeroU64with a guaranteed size and alignment of8. - A big-endian
NonZeroU128with a guaranteed size and alignment of16. - A little-endian
NonZeroU128with a guaranteed size and alignment of16. - A big-endian
u32with a guaranteed size and alignment of4. - A little-endian
u32with a guaranteed size and alignment of4. - A big-endian
f32with a guaranteed size and alignment of4. - A little-endian
f32with a guaranteed size and alignment of4. - A big-endian
f64with a guaranteed size and alignment of8. - A little-endian
f64with a guaranteed size and alignment of8. - A big-endian
i16with a guaranteed size and alignment of2. - A little-endian
i16with a guaranteed size and alignment of2. - A big-endian
i32with a guaranteed size and alignment of4. - A little-endian
i32with a guaranteed size and alignment of4. - A big-endian
i64with a guaranteed size and alignment of8. - A little-endian
i64with a guaranteed size and alignment of8. - A big-endian
i128with a guaranteed size and alignment of16. - A little-endian
i128with a guaranteed size and alignment of16. - A big-endian
u16with a guaranteed size and alignment of2. - A little-endian
u16with a guaranteed size and alignment of2. - A big-endian
u32with a guaranteed size and alignment of4. - A little-endian
u32with a guaranteed size and alignment of4. - A big-endian
u64with a guaranteed size and alignment of8. - A little-endian
u64with a guaranteed size and alignment of8. - A big-endian
u128with a guaranteed size and alignment of16. - A little-endian
u128with a guaranteed size and alignment of16.