Type Definition lazy_transducer::ScrollTransducer [] [src]

type ScrollTransducer<'a, Output, Ctx = Endian> = LazyTransducer<'a, (&'a [u8], Ctx), Output>;

A scroll-based transducer only requires a parsing context for construction. The correct method is statically dispatched according to the output type, and the bounds are checked according to the size of the input and the number of elements requested from the byte source.

In order to use this, you must implement TryFromCtx and SizeWith, which you can usually derive with #[derive(Pread, SizeWith)]

Example

extern crate lazy_transducer;
#[macro_use]
extern crate scroll;
use lazy_transducer::ScrollTransducer;

#[derive(Debug, Pread, SizeWith)]
#[repr(C)]
pub struct Rel {
    pub r_offset: u32,
    pub r_info: u32,
}

let bytes = vec![4, 0, 0, 0, 5, 0, 0, 0, 1, 0, 0, 0, 5, 0, 0, 0];
let lt: ScrollTransducer<Rel, scroll::Endian> = ScrollTransducer::parse_with(&bytes, 2, scroll::LE).unwrap();
for reloc in lt.into_iter() {
  assert_eq!(reloc.r_info, 5);
  println!("{:?}", reloc);
}

Methods

impl<'a, Output, Ctx, E> ScrollTransducer<'a, Output, Ctx> where
    Ctx: Copy + Default,
    Output: 'a + TryFromCtx<'a, Ctx, Error = E, Size = usize> + SizeWith<Ctx, Units = usize>,
    E: From<Error> + Debug
[src]

[src]

Create a new scroll-based lazy transducer, using the given context to parse count elements out of contents

Example

extern crate lazy_transducer;
extern crate rayon;
use lazy_transducer::{ScrollTransducer, Endian};
use rayon::prelude::*;

let bytes = vec![1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 0xef, 0xbe, 0xad, 0xde];
let lt: ScrollTransducer<u32> = ScrollTransducer::parse_with(&bytes, 4, Endian::Little).unwrap();

let deadbeef = lt.get(3).expect("has 4 elements");
assert_eq!(deadbeef, 0xdeadbeef);

lt.into_par_iter().for_each(|n| {
  println!("{:?}", n);
});