[−][src]Struct lazy_transducer::Builder
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,
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]
self
) -> Result<LazyTransducer<'a, Input, Output>, TransducerError>
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,
Input: RefUnwindSafe,
Output: RefUnwindSafe,
impl<'a, Input, Output> Send for Builder<'a, Input, Output> where
Input: Send + Sync,
Output: Sync,
Input: Send + Sync,
Output: Sync,
impl<'a, Input, Output> Sync for Builder<'a, Input, Output> where
Input: Sync,
Output: Sync,
Input: Sync,
Output: Sync,
impl<'a, Input, Output> Unpin for Builder<'a, Input, Output> where
Input: Unpin,
Input: Unpin,
impl<'a, Input, Output> UnwindSafe for Builder<'a, Input, Output> where
Input: RefUnwindSafe + UnwindSafe,
Output: RefUnwindSafe,
Input: RefUnwindSafe + UnwindSafe,
Output: RefUnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,