ToTokens

Trait ToTokens 

Source
pub trait ToTokens<'a> {
    type Iter: Iterator<Item = &'a str>;

    // Required method
    fn to_tokens(&'a self) -> Self::Iter;

    // Provided method
    fn parse_tokens<T>(&'a self) -> Result<T, T::Error>
       where T: FromTokens { ... }
}
Expand description

A trait for types that can be used to create an iterator of tokens.

It can be used to easily parse strings.

Required Associated Types§

Source

type Iter: Iterator<Item = &'a str>

Required Methods§

Source

fn to_tokens(&'a self) -> Self::Iter

Creates an iterator of tokens contained in the type.

Provided Methods§

Source

fn parse_tokens<T>(&'a self) -> Result<T, T::Error>
where T: FromTokens,

Parses all tokens into an (usually inferred) type.

§Example
let (a, b): (u64, char) = "15 B".parse_tokens()?;

assert_eq!(a, 15);
assert_eq!(b, 'B');

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> ToTokens<'a> for str

Source§

fn to_tokens(&'a self) -> Self::Iter

Splits the string by any whitespace (including newlines).

Source§

type Iter = SplitWhitespace<'a>

Implementors§