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

pub trait ScanFromStr<'a>: Sized {
    type Output;
    fn scan_from(s: &'a str) -> Result<(Self::Output, usize)ScanErrorKind>;
}

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

type Output

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

fn scan_from(s: &'a str) -> Result<(Self::Output, usize)ScanErrorKind>

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.

Implementors