tarrasque
A library for zero-allocation parsing of binary formats.
Released under the Apache License 2.0.
Example
use ;
extract!
A library for zero-allocation parsing of binary formats.
Released under the Apache License 2.0.
use tarrasque::{Endianness, Stream};
extract! {
/// A 2D point.
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub Point[4](endianness: Endianness) {
/// The x-coordinate of this point.
x: u16 = ([extract(endianness)]),
/// The y-coordinate of this point.
y: u16 = ([extract(endianness)]),
}
}
fn main() {
let mut stream = Stream(&[1, 2, 3, 4, 5, 6, 7, 8]);
println!("{:?}", stream.extract::<Point, _>(Endianness::Big));
// Ok(Point { x: 258, y: 772 })
println!("{:?}", stream.extract::<Point, _>(Endianness::Little));
// Ok(Point { x: 1541, y: 2055 })
println!("{:?}", stream.extract::<Point, _>(Endianness::Big));
// Err(Insufficient(2))
}