pub trait ScanFromStr<'a>: Sized {
type Output;
// Required method
fn scan_from<I: ScanInput<'a>>(
s: I,
) -> Result<(Self::Output, usize), ScanError>;
// Provided method
fn wants_leading_junk_stripped() -> bool { ... }
}
Expand description
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
.
Required Associated Types§
Required Methods§
Provided Methods§
Sourcefn wants_leading_junk_stripped() -> bool
fn wants_leading_junk_stripped() -> bool
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.
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.