#endian #no-std #transmute #rend

no-std rend

Cross-platform, endian-aware primitives for Rust

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

#174 in Encoding

Download history 483781/week @ 2025-01-29 548637/week @ 2025-02-05 520001/week @ 2025-02-12 599573/week @ 2025-02-19 608756/week @ 2025-02-26 635520/week @ 2025-03-05 652239/week @ 2025-03-12 625527/week @ 2025-03-19 597559/week @ 2025-03-26 598191/week @ 2025-04-02 607123/week @ 2025-04-09 556597/week @ 2025-04-16 570097/week @ 2025-04-23 509243/week @ 2025-04-30 572089/week @ 2025-05-07 487241/week @ 2025-05-14

2,257,129 downloads per month
Used in 697 crates (6 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–335KB