tarrasque 0.8.0

A library for zero-allocation parsing of binary formats.
Documentation

A library for zero-allocation parsing of binary formats.

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() {
let mut stream = Stream(&[1, 2, 3, 4, 5, 6, 7, 8]);

let point = stream.extract::<Point, _>(Endianness::Big);
assert_eq!(point, Ok(Point { x: 258, y: 772 }));

let point = stream.extract::<Point, _>(Endianness::Little);
assert_eq!(point, Ok(Point { x: 1541, y: 2055 }));

let point = stream.extract::<Point, _>(Endianness::Big);
assert_eq!(point, Err(ExtractError::Insufficient(2)));
}