[][src]Struct rcombinators::combinators::Lazy

pub struct Lazy<P, F: FnMut() -> P>(_, _);

Lazy is a helper for a typical situation where you have an Alternative or a Sequence and don't want to construct an expensive parser every time just in order for it to be dropped without having parsed anything. For example:

This example is not tested
// Let's say dict is really expensive! the first ones not as much
let mut p = Alternative::new((number(), string(), atom(), dict()));

Then you can wrap the dict parser constructor in a Lazy parser. Then it will only be constructed if the Alternative actually needs a dict parser:

This example is not tested
let mut p = Alternative::new((number(), string(), atom(), Lazy::new(dict)));

Constructing a Lazy combinator is in comparison quite cheap, as it only involves copying a function pointer. Lazy also caches the result of the function, meaning it will be called at most once.

Methods

impl<R, P: Parser<Result = R>, F: FnMut() -> P> Lazy<P, F>[src]

pub fn new(f: F) -> Lazy<P, F>[src]

Create a new instance of Lazy:

This example is not tested
let l = Lazy::new(|| some_expensive_function());

Trait Implementations

impl<R, P: Parser<Result = R>, F: FnMut() -> P> Parser for Lazy<P, F>[src]

type Result = R

fn apply<R2, F: Fn(Self::Result) -> ParseResult<R2>>(
    self,
    f: F
) -> Transform<Self::Result, R2, Self, F> where
    Self: Sized
[src]

apply transforms the result of this parser using a Transform combinator.

fn then<R2, P: Parser<Result = R2>>(self, p: P) -> Then<Self, P> where
    Self: Sized
[src]

then attempts to parse input, and if it succeeds, executes parser p, only returning p's result. This is useful for chaining parsers of which the results are not need. Read more

Auto Trait Implementations

impl<P, F> Send for Lazy<P, F> where
    F: Send,
    P: Send

impl<P, F> Sync for Lazy<P, F> where
    F: Sync,
    P: Sync

Blanket Implementations

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

impl<T> From<T> for 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.

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

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

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