3 releases

0.1.2 Jan 26, 2023
0.1.1 Apr 15, 2019
0.1.0 Apr 11, 2019

#2776 in Parser implementations

Download history 1/week @ 2024-07-13 3/week @ 2024-07-20 30/week @ 2024-07-27 1/week @ 2024-08-03 1/week @ 2024-08-24 1/week @ 2024-08-31 9/week @ 2024-09-21 1/week @ 2024-09-28

69 downloads per month
Used in brawllib_rs

MIT license

14KB
281 lines

Fancy Slice

Build Status dependency status Crates.io Docs

Wraps an &[u8] slice to provide a kitchen sink worth of tools. Useful for writing a binary format parser that needs to be reverse engineered as you go.

Mostly untested, so gauranteed to have off-by-one errors. :P

Enable the debug feature to add extra functions. You should only enable the debug feature during development as it comes with a performance hit due to storing extra data in FancySlice.

use fancy_slice::FancySlice;

fn main() {
    let data = vec!(4, 1, 3);
    let fancy_slice = FancySlice::new(&data);
    assert_eq!(fancy_slice.u8(0), 4);
    assert_eq!(fancy_slice.u8(1), 1);
    assert_eq!(fancy_slice.u8(2), 3);
    assert_eq!(fancy_slice.u16_be(0), 0x0401);
    assert_eq!(fancy_slice.u16_be(1), 0x0103);

    let inner_fancy_slice = fancy_slice.relative_fancy_slice(1..);
    assert_eq!(inner_fancy_slice.u8(0), 1);
    assert_eq!(inner_fancy_slice.u8(1), 3);
    assert_eq!(inner_fancy_slice.u16_be(0), 0x0103);
}

Dependencies

~115KB