Trait ScanFromStr

Source
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§

Source

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§

Source

fn scan_from<I: ScanInput<'a>>(s: I) -> Result<(Self::Output, usize), ScanError>

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§

Source

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.

Implementations on Foreign Types§

Source§

impl<'a> ScanFromStr<'a> for SocketAddr

Source§

impl<'a> ScanFromStr<'a> for bool

Source§

impl<'a> ScanFromStr<'a> for char

Source§

impl<'a> ScanFromStr<'a> for f32

Source§

impl<'a> ScanFromStr<'a> for f64

Source§

impl<'a> ScanFromStr<'a> for i8

Source§

impl<'a> ScanFromStr<'a> for i16

Source§

impl<'a> ScanFromStr<'a> for i32

Source§

impl<'a> ScanFromStr<'a> for i64

Source§

impl<'a> ScanFromStr<'a> for isize

Source§

impl<'a> ScanFromStr<'a> for u8

Source§

impl<'a> ScanFromStr<'a> for u16

Source§

impl<'a> ScanFromStr<'a> for u32

Source§

impl<'a> ScanFromStr<'a> for u64

Source§

impl<'a> ScanFromStr<'a> for ()

Source§

impl<'a> ScanFromStr<'a> for usize

Source§

impl<'a> ScanFromStr<'a> for String

Source§

impl<'a> ScanFromStr<'a> for Ipv4Addr

Source§

impl<'a> ScanFromStr<'a> for Ipv6Addr

Source§

impl<'a> ScanFromStr<'a> for SocketAddrV4

Source§

impl<'a> ScanFromStr<'a> for SocketAddrV6

Source§

impl<'a> ScanFromStr<'a> for RangeFull

Source§

impl<'a, K, V> ScanFromStr<'a> for BTreeMap<K, V>
where K: ScanFromStr<'a, Output = K> + Ord, V: ScanFromStr<'a, Output = V>,

Source§

type Output = BTreeMap<<K as ScanFromStr<'a>>::Output, <V as ScanFromStr<'a>>::Output>

Source§

fn scan_from<I: ScanInput<'a>>(s: I) -> Result<(Self::Output, usize), ScanError>

Source§

impl<'a, K, V> ScanFromStr<'a> for HashMap<K, V>
where K: ScanFromStr<'a, Output = K> + Hash + Eq, V: ScanFromStr<'a, Output = V>,

Source§

type Output = HashMap<<K as ScanFromStr<'a>>::Output, <V as ScanFromStr<'a>>::Output>

Source§

fn scan_from<I: ScanInput<'a>>(s: I) -> Result<(Self::Output, usize), ScanError>

Source§

impl<'a, T0, T1, T2, T3> ScanFromStr<'a> for (T0, T1, T2, T3)
where T0: ScanFromStr<'a>, T1: ScanFromStr<'a>, T2: ScanFromStr<'a>, T3: ScanFromStr<'a>,

Source§

type Output = (<T0 as ScanFromStr<'a>>::Output, <T1 as ScanFromStr<'a>>::Output, <T2 as ScanFromStr<'a>>::Output, <T3 as ScanFromStr<'a>>::Output)

Source§

fn scan_from<I: ScanInput<'a>>(s: I) -> Result<(Self::Output, usize), ScanError>

Source§

impl<'a, T1, T2, T3> ScanFromStr<'a> for (T1, T2, T3)
where T1: ScanFromStr<'a>, T2: ScanFromStr<'a>, T3: ScanFromStr<'a>,

Source§

type Output = (<T1 as ScanFromStr<'a>>::Output, <T2 as ScanFromStr<'a>>::Output, <T3 as ScanFromStr<'a>>::Output)

Source§

fn scan_from<I: ScanInput<'a>>(s: I) -> Result<(Self::Output, usize), ScanError>

Source§

impl<'a, T2, T3> ScanFromStr<'a> for (T2, T3)
where T2: ScanFromStr<'a>, T3: ScanFromStr<'a>,

Source§

type Output = (<T2 as ScanFromStr<'a>>::Output, <T3 as ScanFromStr<'a>>::Output)

Source§

fn scan_from<I: ScanInput<'a>>(s: I) -> Result<(Self::Output, usize), ScanError>

Source§

impl<'a, T3> ScanFromStr<'a> for (T3,)
where T3: ScanFromStr<'a>,

Source§

type Output = (<T3 as ScanFromStr<'a>>::Output,)

Source§

fn scan_from<I: ScanInput<'a>>(s: I) -> Result<(Self::Output, usize), ScanError>

Source§

impl<'a, T> ScanFromStr<'a> for Option<T>
where T: ScanFromStr<'a>,

Source§

impl<'a, T> ScanFromStr<'a> for [T; 0]

Source§

impl<'a, T> ScanFromStr<'a> for [T; 1]
where T: ScanFromStr<'a>,

Source§

type Output = [<T as ScanFromStr<'a>>::Output; 1]

Source§

fn scan_from<I: ScanInput<'a>>(s: I) -> Result<(Self::Output, usize), ScanError>

Source§

impl<'a, T> ScanFromStr<'a> for [T; 2]
where T: ScanFromStr<'a>,

Source§

type Output = [<T as ScanFromStr<'a>>::Output; 2]

Source§

fn scan_from<I: ScanInput<'a>>(s: I) -> Result<(Self::Output, usize), ScanError>

Source§

impl<'a, T> ScanFromStr<'a> for [T; 3]
where T: ScanFromStr<'a>,

Source§

type Output = [<T as ScanFromStr<'a>>::Output; 3]

Source§

fn scan_from<I: ScanInput<'a>>(s: I) -> Result<(Self::Output, usize), ScanError>

Source§

impl<'a, T> ScanFromStr<'a> for [T; 4]
where T: ScanFromStr<'a>,

Source§

type Output = [<T as ScanFromStr<'a>>::Output; 4]

Source§

fn scan_from<I: ScanInput<'a>>(s: I) -> Result<(Self::Output, usize), ScanError>

Source§

impl<'a, T> ScanFromStr<'a> for [T; 5]
where T: ScanFromStr<'a>,

Source§

type Output = [<T as ScanFromStr<'a>>::Output; 5]

Source§

fn scan_from<I: ScanInput<'a>>(s: I) -> Result<(Self::Output, usize), ScanError>

Source§

impl<'a, T> ScanFromStr<'a> for [T; 6]
where T: ScanFromStr<'a>,

Source§

type Output = [<T as ScanFromStr<'a>>::Output; 6]

Source§

fn scan_from<I: ScanInput<'a>>(s: I) -> Result<(Self::Output, usize), ScanError>

Source§

impl<'a, T> ScanFromStr<'a> for [T; 7]
where T: ScanFromStr<'a>,

Source§

type Output = [<T as ScanFromStr<'a>>::Output; 7]

Source§

fn scan_from<I: ScanInput<'a>>(s: I) -> Result<(Self::Output, usize), ScanError>

Source§

impl<'a, T> ScanFromStr<'a> for [T; 8]
where T: ScanFromStr<'a>,

Source§

type Output = [<T as ScanFromStr<'a>>::Output; 8]

Source§

fn scan_from<I: ScanInput<'a>>(s: I) -> Result<(Self::Output, usize), ScanError>

Source§

impl<'a, T> ScanFromStr<'a> for BinaryHeap<T>
where T: ScanFromStr<'a, Output = T> + Ord,

Source§

impl<'a, T> ScanFromStr<'a> for BTreeSet<T>
where T: ScanFromStr<'a, Output = T> + Ord,

Source§

impl<'a, T> ScanFromStr<'a> for LinkedList<T>
where T: ScanFromStr<'a, Output = T>,

Source§

impl<'a, T> ScanFromStr<'a> for VecDeque<T>
where T: ScanFromStr<'a, Output = T>,

Source§

impl<'a, T> ScanFromStr<'a> for Vec<T>
where T: ScanFromStr<'a, Output = T>,

Source§

type Output = Vec<<T as ScanFromStr<'a>>::Output>

Source§

fn scan_from<I: ScanInput<'a>>(s: I) -> Result<(Self::Output, usize), ScanError>

Source§

impl<'a, T> ScanFromStr<'a> for Range<T>
where T: ScanFromStr<'a, Output = T>,

Source§

type Output = Range<<T as ScanFromStr<'a>>::Output>

Source§

fn scan_from<I: ScanInput<'a>>(s: I) -> Result<(Self::Output, usize), ScanError>

Source§

impl<'a, T> ScanFromStr<'a> for RangeFrom<T>
where T: ScanFromStr<'a, Output = T>,

Source§

impl<'a, T> ScanFromStr<'a> for RangeTo<T>
where T: ScanFromStr<'a, Output = T>,

Source§

impl<'a, T> ScanFromStr<'a> for HashSet<T>
where T: ScanFromStr<'a, Output = T> + Hash + Eq,

Source§

impl<'a, T, E> ScanFromStr<'a> for Result<T, E>
where T: ScanFromStr<'a>, E: ScanFromStr<'a>,

Source§

type Output = Result<<T as ScanFromStr<'a>>::Output, <E as ScanFromStr<'a>>::Output>

Source§

fn scan_from<I: ScanInput<'a>>(s: I) -> Result<(Self::Output, usize), ScanError>

Implementors§

Source§

impl<'a> ScanFromStr<'a> for QuotedString

Source§

impl<'a> ScanFromStr<'a> for Iso8601Duration

Source§

impl<'a, K, V> ScanFromStr<'a> for KeyValuePair<K, V>
where K: ScanSelfFromStr<'a>, V: ScanSelfFromStr<'a>,

Source§

impl<'a, Output> ScanFromStr<'a> for Binary<Output>
where Output: ScanFromBinary<'a>,

Source§

type Output = Output

Source§

impl<'a, Output> ScanFromStr<'a> for Everything<'a, Output>
where &'a str: Into<Output>,

Source§

type Output = Output

Source§

impl<'a, Output> ScanFromStr<'a> for Hex<Output>
where Output: ScanFromHex<'a>,

Source§

type Output = Output

Source§

impl<'a, Output> ScanFromStr<'a> for HorSpace<'a, Output>
where &'a str: Into<Output>,

Source§

type Output = Output

Source§

impl<'a, Output> ScanFromStr<'a> for Ident<'a, Output>
where &'a str: Into<Output>,

Source§

type Output = Output

Source§

impl<'a, Output> ScanFromStr<'a> for Line<'a, Output>
where &'a str: Into<Output>,

Source§

type Output = Output

Source§

impl<'a, Output> ScanFromStr<'a> for Newline<'a, Output>
where &'a str: Into<Output>,

Source§

type Output = Output

Source§

impl<'a, Output> ScanFromStr<'a> for NonSpace<'a, Output>
where &'a str: Into<Output>,

Source§

type Output = Output

Source§

impl<'a, Output> ScanFromStr<'a> for Number<'a, Output>
where &'a str: Into<Output>,

Source§

type Output = Output

Source§

impl<'a, Output> ScanFromStr<'a> for Octal<Output>
where Output: ScanFromOctal<'a>,

Source§

type Output = Output

Source§

impl<'a, Output> ScanFromStr<'a> for Space<'a, Output>
where &'a str: Into<Output>,

Source§

type Output = Output

Source§

impl<'a, Output> ScanFromStr<'a> for Word<'a, Output>
where &'a str: Into<Output>,

Source§

type Output = Output

Source§

impl<'a, Output> ScanFromStr<'a> for Wordish<'a, Output>
where &'a str: Into<Output>,

Source§

type Output = Output

Source§

impl<'a, T> ScanFromStr<'a> for Inferred<T>
where T: ScanSelfFromStr<'a>,