tarrasque

Crates.iotarrasque
lib.rstarrasque
version0.10.0
sourcesrc
created_at2018-04-25 08:31:37.6646
updated_at2019-01-01 21:26:23.436845
descriptionA library for zero-allocation parsing of binary formats.
homepage
repositoryhttps://github.com/glyph-rs/tarrasque
max_upload_size
id62214
size40,717
Kyle Mayes (KyleMayes)

documentation

https://docs.rs/tarrasque

README

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

cargo fmt