[][src]Struct shtring::Parser

pub struct Parser<'a> { /* fields omitted */ }

Iterator over the arguments in an input string.

The individual returned items for an input string &'a str are Result<&'a str, Error> (see error-handling below for notes on the individual results). Escape sequences in the format \<character> are parsed as normal characters. The iterator will return None once the input has been exhausted.

let input = "a \"b c\" \\\"d";
let mut parser = Parser::new(input);
assert_eq!(parser.next(), Some(Ok("a")));
assert_eq!(parser.next(), Some(Ok("b c")));
assert_eq!(parser.next(), Some(Ok("\\\"d")));
assert_eq!(parser.next(), None);

Error handling

The parser will recover from any errors encountered while parsing individual arguments. This means that if some argument fails to be parsed, there still may be more valid arguments after it, in the sense that the erroneous argument was ignored.

let input = "a b\" c";
let mut parser = Parser::new(input);
assert_eq!(parser.next(), Some(Ok("a")));
assert_eq!(parser.next(), Some(Err(Error::UnexpectedToken(3, "\""))));
assert_eq!(parser.next(), Some(Ok("c")));
assert_eq!(parser.next(), None);

Implementations

impl<'a> Parser<'a>[src]

pub fn new(input: &'a str) -> Self[src]

Return a new Parser over a given input string.

Trait Implementations

impl<'a> Debug for Parser<'a>[src]

impl<'a> Iterator for Parser<'a>[src]

type Item = Result<&'a str, Error<'a>>

The type of the elements being iterated over.

Auto Trait Implementations

impl<'a> RefUnwindSafe for Parser<'a>

impl<'a> Send for Parser<'a>

impl<'a> Sync for Parser<'a>

impl<'a> Unpin for Parser<'a>

impl<'a> UnwindSafe for Parser<'a>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.