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

#138 in Encoding

Download history 647396/week @ 2025-03-10 633464/week @ 2025-03-17 615699/week @ 2025-03-24 586182/week @ 2025-03-31 621161/week @ 2025-04-07 573747/week @ 2025-04-14 573377/week @ 2025-04-21 506876/week @ 2025-04-28 540521/week @ 2025-05-05 601068/week @ 2025-05-12 636059/week @ 2025-05-19 563416/week @ 2025-05-26 668357/week @ 2025-06-02 662896/week @ 2025-06-09 697445/week @ 2025-06-16 700962/week @ 2025-06-23

2,752,092 downloads per month
Used in 717 crates (7 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–330KB