Struct pest::iterators::Pair
[−]
[src]
pub struct Pair<R, I: Input> { /* fields omitted */ }
A struct
containing a matching pair of Token
s 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 Token
s 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
[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);
fn as_str(&self) -> &str
[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");
fn into_span(self) -> Span<I>
[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");
fn into_inner(self) -> Pairs<R, I>
[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());
fn tokens(self) -> TokenIterator<R, I>
[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]
fn clone(&self) -> Pair<R, I>
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl<R: RuleType, I: Input> Debug for Pair<R, I>
[src]
impl<R: RuleType, I: Input> Display for Pair<R, I>
[src]
fn fmt(&self, f: &mut Formatter) -> Result
[src]
Formats the value using the given formatter. Read more
impl<R: PartialEq, I: Input> PartialEq for Pair<R, I>
[src]
fn eq(&self, other: &Pair<R, I>) -> bool
[src]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.