4 stable releases

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

#295 in Encoding

Download history 9/week @ 2024-01-03 7/week @ 2024-01-10 10/week @ 2024-01-17 5/week @ 2024-01-24 9/week @ 2024-01-31 379/week @ 2024-02-07 1777/week @ 2024-02-14 4816/week @ 2024-02-21 7060/week @ 2024-02-28 8398/week @ 2024-03-06 9808/week @ 2024-03-13 11693/week @ 2024-03-20 11742/week @ 2024-03-27 15051/week @ 2024-04-03 17652/week @ 2024-04-10 16952/week @ 2024-04-17

63,324 downloads per month
Used in 69 crates (via zvariant)

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