Crate tarrasque [−] [src]
A library for zero-allocation parsing of binary formats.
Example
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)) }
Macros
extract |
Defines a struct with a corresponding [ |
Structs
Stream |
A stream of bytes from which values can be extracted. |
UnwrapStream |
A [ |
View |
A slice of bytes containing values that span a fixed number of bytes. |
ViewIter |
An iterator over the values in a [ |
Enums
Endianness |
A byte order. |
ExtractError |
An error encountered while extracting a value from a stream of bytes. |
Traits
Extract |
A type that can be extracted from a stream of bytes. |
Span |
A type that spans a fixed number of bytes. |
Functions
be_f32 |
Returns the first four bytes in the supplied slice as a big-endian |
be_f64 |
Returns the first eight bytes in the supplied slice as a big-endian |
be_i16 |
Returns the first two bytes in the supplied slice as a big-endian |
be_i32 |
Returns the first four bytes in the supplied slice as a big-endian |
be_i64 |
Returns the first eight bytes in the supplied slice as a big-endian |
be_u16 |
Returns the first two bytes in the supplied slice as a big-endian |
be_u32 |
Returns the first four bytes in the supplied slice as a big-endian |
be_u64 |
Returns the first eight bytes in the supplied slice as a big-endian |
le_f32 |
Returns the first four bytes in the supplied slice as a little-endian |
le_f64 |
Returns the first eight bytes in the supplied slice as a little-endian |
le_i16 |
Returns the first two bytes in the supplied slice as a little-endian |
le_i32 |
Returns the first four bytes in the supplied slice as a little-endian |
le_i64 |
Returns the first eight bytes in the supplied slice as a little-endian |
le_u16 |
Returns the first two bytes in the supplied slice as a little-endian |
le_u32 |
Returns the first four bytes in the supplied slice as a little-endian |
le_u64 |
Returns the first eight bytes in the supplied slice as a little-endian |
Type Definitions
ExtractResult |
The result of extracting a value from a stream of bytes. |