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

#133 in Encoding

Download history 350936/week @ 2024-10-28 338814/week @ 2024-11-04 365701/week @ 2024-11-11 370152/week @ 2024-11-18 321982/week @ 2024-11-25 379138/week @ 2024-12-02 379177/week @ 2024-12-09 354797/week @ 2024-12-16 193402/week @ 2024-12-23 233408/week @ 2024-12-30 519663/week @ 2025-01-06 564048/week @ 2025-01-13 475294/week @ 2025-01-20 481885/week @ 2025-01-27 529745/week @ 2025-02-03 516579/week @ 2025-02-10

2,029,783 downloads per month
Used in 645 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–370KB