[][src]Struct lazy_transducer::Builder

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]

pub fn empty() -> Self[src]

Creates an empty builder; you must set the input and transducer before calling finish otherwise this is a runtime error.

pub 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.

pub fn input(self, input: Input) -> Self[src]

Set (or reset) the input.

pub fn count(self, count: usize) -> Self[src]

Set the number of output elements in the input source.

pub fn transducer(self, transducer: fn(_: Input, _: usize) -> Output) -> Self[src]

Set the transducer from input source to output elements.

pub fn finish(
    self
) -> Result<LazyTransducer<'a, Input, Output>, TransducerError>
[src]

Finish building the lazy transducer, and return it; if the input source or the transducer is missing this is a runtime error.

Auto Trait Implementations

impl<'a, Input, Output> RefUnwindSafe for Builder<'a, Input, Output> where
    Input: RefUnwindSafe,
    Output: RefUnwindSafe

impl<'a, Input, Output> Send for Builder<'a, Input, Output> where
    Input: Send + Sync,
    Output: Sync

impl<'a, Input, Output> Sync for Builder<'a, Input, Output> where
    Input: Sync,
    Output: Sync

impl<'a, Input, Output> Unpin for Builder<'a, Input, Output> where
    Input: Unpin

impl<'a, Input, Output> UnwindSafe for Builder<'a, Input, Output> where
    Input: RefUnwindSafe + UnwindSafe,
    Output: RefUnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.