rend

Crates.iorend
lib.rsrend
version0.5.2
sourcesrc
created_at2021-05-03 04:50:08.31116
updated_at2024-10-10 22:58:02.496159
descriptionCross-platform, endian-aware primitives for Rust
homepage
repositoryhttps://github.com/djkoloski/rend
max_upload_size
id392405
size98,544
David Koloski (djkoloski)

documentation

https://docs.rs/rend

README

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));
Commit count: 60

cargo fmt