Trait ScanCursor

Source
pub trait ScanCursor<'a>:
    'a
    + Sized
    + Clone {
    type ScanInput: ScanInput<'a>;

    // Required methods
    fn try_end(self) -> Result<(), (ScanError, Self)>;
    fn try_scan<F, Out>(self, f: F) -> Result<(Out, Self), (ScanError, Self)>
       where F: FnOnce(Self::ScanInput) -> Result<(Out, usize), ScanError>;
    fn try_scan_raw<F, Out>(
        self,
        f: F,
    ) -> Result<(Out, Self), (ScanError, Self)>
       where F: FnOnce(Self::ScanInput) -> Result<(Out, usize), ScanError>;
    fn try_match_literal(self, lit: &str) -> Result<Self, (ScanError, Self)>;
    fn as_str(self) -> &'a str;
    fn offset(&self) -> usize;
}
Expand description

This trait defines the interface to input values that can be scanned.

Required Associated Types§

Source

type ScanInput: ScanInput<'a>

Corresponding scan input type.

Required Methods§

Source

fn try_end(self) -> Result<(), (ScanError, Self)>

Assert that the input has been exhausted, or that the current position is a valid place to “stop”.

Source

fn try_scan<F, Out>(self, f: F) -> Result<(Out, Self), (ScanError, Self)>
where F: FnOnce(Self::ScanInput) -> Result<(Out, usize), ScanError>,

Scan a value from the current position. The closure will be called with all available input, and is expected to return either the scanned value, and the number of bytes of input consumed, or a reason why scanning failed.

The input will have all leading whitespace removed, if applicable.

Source

fn try_scan_raw<F, Out>(self, f: F) -> Result<(Out, Self), (ScanError, Self)>
where F: FnOnce(Self::ScanInput) -> Result<(Out, usize), ScanError>,

Performs the same task as try_scan, except that it does not perform whitespace stripping.

Source

fn try_match_literal(self, lit: &str) -> Result<Self, (ScanError, Self)>

Match the provided literal term against the input.

Implementations are free to interpret “match” as they please.

Source

fn as_str(self) -> &'a str

Returns the remaining input as a string slice.

Source

fn offset(&self) -> usize

Returns the number of bytes consumed by this cursor since its creation.

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.

Implementors§

Source§

impl<'a, Cmp, Space, Word> ScanCursor<'a> for StrCursor<'a, Cmp, Space, Word>
where Cmp: StrCompare, Space: SkipSpace, Word: SliceWord,

Source§

type ScanInput = StrCursor<'a, Cmp, Space, Word>