23 releases

0.5.0-pre6 Jan 1, 2024
0.5.0-pre5 Dec 15, 2023
0.5.0-pre2 Nov 4, 2023
0.5.0-alpha.7 Mar 30, 2024
0.3.1 Jul 6, 2021

#86 in Encoding

Download history 128341/week @ 2023-12-23 183954/week @ 2023-12-30 228711/week @ 2024-01-06 246206/week @ 2024-01-13 260889/week @ 2024-01-20 287495/week @ 2024-01-27 292295/week @ 2024-02-03 281117/week @ 2024-02-10 260251/week @ 2024-02-17 283428/week @ 2024-02-24 302399/week @ 2024-03-02 315966/week @ 2024-03-09 332039/week @ 2024-03-16 323676/week @ 2024-03-23 324724/week @ 2024-03-30 269826/week @ 2024-04-06

1,306,530 downloads per month
Used in 388 crates (5 directly)

MIT license

79KB
2K SLoC

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


rend in action

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));

lib.rs:

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 using bytecheck

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));

Dependencies

~135KB