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]
fn as_rule(&self) -> R
Returns the Rule of the Pair.
Example
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);
fn into_span(self) -> Span<I>
Returns the Span defined by the Pair, consuming it.
Example
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");
fn into_inner(self) -> Pairs<R, I>
Returns the inner Pairs between the Pair, consuming it.
Example
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());
fn into_iter(self) -> TokenIterator<R, I>
Converts the Pair into a TokenIterator.
Example
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.into_iter().collect(); assert_eq!(tokens.len(), 2);
Trait Implementations
impl<R: RuleType, I: Input> Debug for Pair<R, I>[src]
impl<R: Clone, I: Input> Clone for Pair<R, I>[src]
fn clone(&self) -> Pair<R, I>
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)1.0.0
Performs copy-assignment from source. Read more