4 stable releases

1.1.0 Dec 12, 2023
1.0.2 Dec 11, 2023
1.0.1 Dec 10, 2023

#315 in Encoding

Download history 26894/week @ 2024-06-13 23897/week @ 2024-06-20 27456/week @ 2024-06-27 29101/week @ 2024-07-04 37087/week @ 2024-07-11 39448/week @ 2024-07-18 42633/week @ 2024-07-25 41685/week @ 2024-08-01 46534/week @ 2024-08-08 41682/week @ 2024-08-15 41015/week @ 2024-08-22 44319/week @ 2024-08-29 48398/week @ 2024-09-05 48936/week @ 2024-09-12 47949/week @ 2024-09-19 46317/week @ 2024-09-26

199,195 downloads per month
Used in 146 crates (3 directly)

MIT license

16KB
316 lines

endi

Build Status API Documentation crates.io

Yet another endian handling library for Rust. The approach is very similar to that of byteordered crate with its Endianness enum, except that endi is much simpler and doesn't depend on byteorder (or anything at all).

Usage

The main type is Endian enum which can be either Big or Little. It provides various methods to read and write integers of different sizes and endianness.

use endi::{Endian, ReadBytes, WriteBytes};

let mut buf = [0u8; 4];
for endian in [Endian::Little, Endian::Big] {
    endian.write_u32(&mut buf, 0xAB_BA_FE_EF);
    assert_eq!(endian.read_u32(&buf), 0xAB_BA_FE_EF);

    // Using the `ReadBytes` and `WriteBytes` traits:
    let mut cursor = std::io::Cursor::new(&mut buf[..]);
    cursor.write_u32(endian, 0xAB_BA_FE_EF).unwrap();
    cursor.set_position(0);
    assert_eq!(cursor.read_u32(endian).unwrap(), 0xAB_BA_FE_EF);
}

nostd

You can disable std by disabling the default std feature. This will disable the ReadBytes and WriteBytes traits.

License

MIT

No runtime deps

Features