Trait scan_rules::scanner::ScanFromStr [] [src]

pub trait ScanFromStr<'a>: Sized {
    type Output;
    fn scan_from<I: ScanInput<'a>>(
        s: I
    ) -> Result<(Self::Output, usize), ScanError>; fn wants_leading_junk_stripped() -> bool { ... } }

This trait defines the interface to a type which can be scanned.

The exact syntax scanned is entirely arbitrary, though there are some rules of thumb that implementations should generally stick to:

  • Do not ignore leading whitespace.
  • Do not eagerly consume trailing whitespace, unless it is legitimately part of the scanned syntax.

In addition, if you are implementing scanning directly for the result type (i.e. Output = Self), prefer parsing only the result of the type's Debug implementation. This ensures that there is a degree of round-tripping between format! and scan!.

If a type has multiple legitimate parsing forms, consider defining those alternate forms on abstract scanner types (i.e. Output != Self) instead.

See: ScanSelfFromStr.

Associated Types

The type that the implementation scans into. This does not have to be the same as the implementing type, although it typically will be.

See: ScanSelfFromStr::scan_self_from.

Required Methods

Perform a scan on the given input.

Implementations must return either the scanned value, and the number of bytes consumed from the input, or a reason why scanning failed.

Provided Methods

Indicates whether or not the scanner wants its input to have leading "junk", such as whitespace, stripped.

The default implementation returns true, which is almost always the correct answer. You should only implement this explicitly (and return false) if you are implementing a scanner for which leading whitespace is important.

Implementors