[−][src]Struct rcombinators::combinators::Lazy
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:
// 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:
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
:
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 parse(
&mut self,
st: &mut ParseState<impl Iterator<Item = char>>
) -> ParseResult<Self::Result>
[src]
&mut self,
st: &mut ParseState<impl Iterator<Item = char>>
) -> ParseResult<Self::Result>
fn apply<R2, F: Fn(Self::Result) -> ParseResult<R2>>(
self,
f: F
) -> Transform<Self::Result, R2, Self, F> where
Self: Sized,
[src]
self,
f: F
) -> Transform<Self::Result, R2, Self, F> where
Self: Sized,
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]
Self: Sized,
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,
F: Send,
P: Send,
impl<P, F> Sync for Lazy<P, F> where
F: Sync,
P: Sync,
F: Sync,
P: Sync,
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
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>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
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> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,