Leaf

Trait Leaf 

Source
pub trait Leaf<'i>: Sized {
    type Output;

    // Required method
    fn parse(&self, input: &'i [u8]) -> LeafResult<'i, Self::Output>;
}
Expand description

Trait implemented by atomic, fail‑fast parsers.

Leaf parsers always return the first error they encounter without backtracking.

Required Associated Types§

Source

type Output

Type of the value produced by parse when successful.

Required Methods§

Source

fn parse(&self, input: &'i [u8]) -> LeafResult<'i, Self::Output>

Parse one item, returning immediately on error without backtracking.

Returns a tuple of the successfully parsed Output value and the remaining bytes, or a tuple containing a ParseError and the location of the error.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<'i> Leaf<'i> for &'static str

Matches the string literal exactly.

Normally used with with_prefix or with_suffix.

Source§

type Output = ()

Source§

fn parse(&self, input: &'i [u8]) -> LeafResult<'i, Self::Output>

Source§

impl<'i> Leaf<'i> for u8

Matches the byte exactly.

Normally used with with_prefix or with_suffix.

Source§

type Output = ()

Source§

fn parse(&self, input: &'i [u8]) -> LeafResult<'i, Self::Output>

Implementors§

Source§

impl<'i, F: Fn(&'i [u8]) -> LeafResult<'i, O>, O> Leaf<'i> for F

Allow custom functions/closures to be used as Leaf parsers.