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]

[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);

[src]

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");

[src]

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");

[src]

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());

[src]

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: Clone, I: Clone + Input> Clone for Pair<R, I>
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

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

[src]

Formats the value using the given formatter.

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

[src]

Formats the value using the given formatter. Read more

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

[src]

This method tests for self and other values to be equal, and is used by ==. Read more

1.0.0
[src]

This method tests for !=.

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

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

[src]

Feeds this value into the given [Hasher]. Read more

1.3.0
[src]

Feeds a slice of this type into the given [Hasher]. Read more