#binary #apache #zero-allocation #formats

tarrasque

A library for zero-allocation parsing of binary formats

9 breaking releases

0.10.0 Jan 1, 2019
0.9.0 Dec 27, 2018
0.8.0 Dec 24, 2018
0.5.0 Jun 17, 2018
Download history 6/week @ 2022-01-27 4/week @ 2022-02-03 2/week @ 2022-02-10 15/week @ 2022-02-17 7/week @ 2022-02-24 4/week @ 2022-03-03 15/week @ 2022-03-10 62/week @ 2022-03-17 5/week @ 2022-03-24 6/week @ 2022-03-31 5/week @ 2022-04-07 5/week @ 2022-04-14 4/week @ 2022-04-21 94/week @ 2022-04-28 75/week @ 2022-05-05 167/week @ 2022-05-12

340 downloads per month
Used in 2 crates

Apache-2.0

34KB
600 lines

tarrasque

crates.io docs.rs travis-ci.com

A library for zero-allocation parsing of binary formats.

Released under the Apache License 2.0.

Supported on Rust 1.31.0 and later.

Example

use tarrasque::{Endianness, ExtractError, Stream, extract};

extract! {
    /// A 2D point.
    #[derive(Copy, Clone, Debug, PartialEq, Eq)]
    pub struct Point[4](endianness: Endianness) {
        /// The x-coordinate of this point.
        pub x: u16 = [endianness],
        /// The y-coordinate of this point.
        pub y: u16 = [endianness],
    }
}

fn main() {
    // A stream of bytes.
    let mut stream = Stream(&[1, 2, 3, 4, 5, 6, 7, 8]);

    // Extract a point containing two big-endian `u16`s from the stream.
    let point = stream.extract::<Point, _>(Endianness::Big);
    assert_eq!(point, Ok(Point { x: 258, y: 772 }));

    // Extract a point containing two little-endian `u16`s from the stream.
    let point = stream.extract::<Point, _>(Endianness::Little);
    assert_eq!(point, Ok(Point { x: 1541, y: 2055 }));

    // Attempt to extract a point from the empty stream.
    let point = stream.extract::<Point, _>(Endianness::Big);
    assert_eq!(point, Err(ExtractError::Insufficient(2)));
}

Dependencies

~1.5MB
~42K SLoC