Struct lazy_transducer::Builder
[−]
[src]
pub struct Builder<'a, Input, Output> where
Input: 'a + Copy,
Output: 'a, { /* fields omitted */ }
A builder is useful for when the transducer needs to be constructed incrementally, i.e., certain information is present later on, or is optional, etc.
Example
use lazy_transducer::{LazyTransducer, Builder}; use std::mem::size_of; use std::mem::transmute; let bytes: Vec<u8> = vec![1u8, 0, 2, 0, 3, 0, 4, 0]; let mut builder = Builder::new(&bytes); let maybe_number_of_elements = Some(4); if let Some(count) = maybe_number_of_elements { builder = builder.count(count); } // if the count was None, we'd have 0 elements, but the transducer is still constructable, // similar to an empty iterator let lt: LazyTransducer<_, u16> = builder.transducer(|input, index| { let start = size_of::<u16>() * index; unsafe { *transmute::<_, &u16>(&input[start]) } }) .finish() .unwrap(); // note: the data will be 1, 2, 3, 4, for little-endian machines, but not for big-endian for (i, n) in lt.into_iter().enumerate() { println!("{}: {}", i, n); }
Methods
impl<'a, Input, Output> Builder<'a, Input, Output> where
Input: 'a + Copy,
Output: 'a,
[src]
Input: 'a + Copy,
Output: 'a,
fn empty() -> Self
[src]
Creates an empty builder; you must set the input and transducer before calling finish
otherwise this is a runtime error.
fn new(input: Input) -> Self
[src]
Create a new builder with the given input
; you must set the transducer before calling finish
otherwise this is a runtime error.
fn input(self, input: Input) -> Self
[src]
Set (or reset) the input.
fn count(self, count: usize) -> Self
[src]
Set the number of output elements in the input source.
fn transducer(self, transducer: fn(_: Input, _: usize) -> Output) -> Self
[src]
Set the transducer from input source to output elements.
fn finish(self) -> Result<LazyTransducer<'a, Input, Output>, Error>
[src]
Finish building the lazy transducer, and return it; if the input source or the transducer is missing this is a runtime error.
impl<'a, Output> Builder<'a, &'a [u8], Output>
[src]
fn parse_with<Ctx, E>(
self,
ctx: Ctx
) -> Result<ScrollTransducer<'a, Output, Ctx>, Error> where
Ctx: Default + Copy,
E: From<Error> + Debug,
Output: 'a + TryFromCtx<'a, Ctx, Error = E, Size = usize> + SizeWith<Ctx, Units = usize>,
[src]
self,
ctx: Ctx
) -> Result<ScrollTransducer<'a, Output, Ctx>, Error> where
Ctx: Default + Copy,
E: From<Error> + Debug,
Output: 'a + TryFromCtx<'a, Ctx, Error = E, Size = usize> + SizeWith<Ctx, Units = usize>,
Create a scroll-based transducer with the given parsing ctx
.