Struct pest::iterators::Pair [] [src]

pub struct Pair<R, I: Input> { /* fields omitted */ }

A struct containing a matching pair of Tokens and everything between them.

A matching Token pair is formed by a Token::Start and a subsequent Token::End with the same Rule, with the condition that all Tokens between them can form such pairs as well. This is similar to the brace matching problem in editors.

Methods

impl<R: RuleType, I: Input> Pair<R, I>
[src]

Returns the Rule of the Pair.

Examples

enum Rule {
    a
}

let input = Rc::new(StringInput::new("".to_owned()));
let pair = pest::state(input, |state, pos| {
    // generating Token pair with Rule::a ...
}).unwrap().next().unwrap();

assert_eq!(pair.as_rule(), Rule::a);

Captures a &str slice from the Input defined by the token Pair.

Examples

enum Rule {
    ab
}

let input = Rc::new(StringInput::new("ab".to_owned()));
let pair = pest::state(input, |state, pos| {
    // generating Token pair with Rule::ab ...
}).unwrap().next().unwrap();

assert_eq!(pair.as_str(), "ab");

Returns the Span defined by the Pair, consuming it.

Examples

enum Rule {
    ab
}

let input = Rc::new(StringInput::new("ab".to_owned()));
let pair = pest::state(input, |state, pos| {
    // generating Token pair with Rule::ab ...
}).unwrap().next().unwrap();

assert_eq!(pair.into_span().as_str(), "ab");

Returns the inner Pairs between the Pair, consuming it.

Examples

enum Rule {
    a
}

let input = Rc::new(StringInput::new("".to_owned()));
let pair = pest::state(input, |state, pos| {
    // generating Token pair with Rule::a ...
}).unwrap().next().unwrap();

assert!(pair.into_inner().next().is_none());

Converts the Pair into a TokenIterator.

Examples

enum Rule {
    a
}

let input = Rc::new(StringInput::new("".to_owned()));
let pair = pest::state(input, |state, pos| {
    // generating Token pair with Rule::a ...
}).unwrap().next().unwrap();
let tokens: Vec<_> = pair.tokens().collect();

assert_eq!(tokens.len(), 2);

Trait Implementations

impl<R: RuleType, I: Input> Debug for Pair<R, I>
[src]

Formats the value using the given formatter.

impl<R: Clone, I: Input> Clone for Pair<R, I>
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more