29 releases

0.5.2 Oct 10, 2024
0.5.0-pre6 Jan 1, 2024
0.5.0-pre5 Dec 15, 2023
0.5.0-pre2 Nov 4, 2023
0.3.1 Jul 6, 2021

#135 in Encoding

Download history 360245/week @ 2024-11-21 345480/week @ 2024-11-28 371198/week @ 2024-12-05 373735/week @ 2024-12-12 247619/week @ 2024-12-19 187473/week @ 2024-12-26 408980/week @ 2025-01-02 579915/week @ 2025-01-09 499881/week @ 2025-01-16 486301/week @ 2025-01-23 495591/week @ 2025-01-30 546636/week @ 2025-02-06 519649/week @ 2025-02-13 618901/week @ 2025-02-20 603640/week @ 2025-02-27 638042/week @ 2025-03-06

2,487,590 downloads per month
Used in 677 crates (5 directly)

MIT license

93KB
2.5K SLoC

rend

crates.io badge docs badge license badge

rend provides cross-platform, endian-aware primitives for Rust.

Documentation

  • rend, provides cross-platform, endian-aware primitives for Rust

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

Dependencies

~0–350KB