Struct Pair

struct Pair<'i, R> { ... }

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.

Implementations

impl<'i, R: RuleType> Pair<'i, R>

fn as_rule(self: &Self) -> R

Returns the Rule of the Pair.

Examples

# use std::rc::Rc;
# use pest;
# #[allow(non_camel_case_types)]
# #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
enum Rule {
    a
}

let input = "";
let pair = pest::state(input, |state| {
    // generating Token pair with Rule::a ...
#     state.rule(Rule::a, |s| Ok(s))
}).unwrap().next().unwrap();

assert_eq!(pair.as_rule(), Rule::a);
fn as_str(self: &Self) -> &'i str

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

Examples

# use std::rc::Rc;
# use pest;
# #[allow(non_camel_case_types)]
# #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
enum Rule {
    ab
}

let input = "ab";
let pair = pest::state(input, |state| {
    // generating Token pair with Rule::ab ...
#     state.rule(Rule::ab, |s| s.match_string("ab"))
}).unwrap().next().unwrap();

assert_eq!(pair.as_str(), "ab");
fn get_input(self: &Self) -> &'i str

Returns the input string of the Pair.

This function returns the input string of the Pair as a &str. This is the source string from which the Pair was created. The returned &str can be used to examine the contents of the Pair or to perform further processing on the string.

Examples

# use std::rc::Rc;
# use pest;
# #[allow(non_camel_case_types)]
# #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
enum Rule {
    ab
}

// Example: Get input string from a Pair

let input = "ab";
let pair = pest::state(input, |state| {
    // generating Token pair with Rule::ab ...
#     state.rule(Rule::ab, |s| s.match_string("ab"))
}).unwrap().next().unwrap();

assert_eq!(pair.as_str(), "ab");
assert_eq!(input, pair.get_input());
fn into_span(self: Self) -> Span<'i>

Returns the Span defined by the Pair, consuming it.

Examples

# use std::rc::Rc;
# use pest;
# #[allow(non_camel_case_types)]
# #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
enum Rule {
    ab
}

let input = "ab";
let pair = pest::state(input, |state| {
    // generating Token pair with Rule::ab ...
#     state.rule(Rule::ab, |s| s.match_string("ab"))
}).unwrap().next().unwrap();

assert_eq!(pair.into_span().as_str(), "ab");
fn as_span(self: &Self) -> Span<'i>

Returns the Span defined by the Pair, without consuming it.

Examples

# use std::rc::Rc;
# use pest;
# #[allow(non_camel_case_types)]
# #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
enum Rule {
    ab
}

let input = "ab";
let pair = pest::state(input, |state| {
    // generating Token pair with Rule::ab ...
#     state.rule(Rule::ab, |s| s.match_string("ab"))
}).unwrap().next().unwrap();

assert_eq!(pair.as_span().as_str(), "ab");
fn as_node_tag(self: &Self) -> Option<&str>

Get current node tag

fn into_inner(self: Self) -> Pairs<'i, R>

Returns the inner Pairs between the Pair, consuming it.

Examples

# use std::rc::Rc;
# use pest;
# #[allow(non_camel_case_types)]
# #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
enum Rule {
    a
}

let input = "";
let pair = pest::state(input, |state| {
    // generating Token pair with Rule::a ...
#     state.rule(Rule::a, |s| Ok(s))
}).unwrap().next().unwrap();

assert!(pair.into_inner().next().is_none());
fn tokens(self: Self) -> Tokens<'i, R>

Returns the Tokens for the Pair.

Examples

# use std::rc::Rc;
# use pest;
# #[allow(non_camel_case_types)]
# #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
enum Rule {
    a
}

let input = "";
let pair = pest::state(input, |state| {
    // generating Token pair with Rule::a ...
#     state.rule(Rule::a, |s| Ok(s))
}).unwrap().next().unwrap();
let tokens: Vec<_> = pair.tokens().collect();

assert_eq!(tokens.len(), 2);
fn line_col(self: &Self) -> (usize, usize)

Returns the line, col of this pair start.

impl<'i, R> Freeze for Pair<'i, R>

impl<'i, R> RefUnwindSafe for Pair<'i, R>

impl<'i, R> Send for Pair<'i, R>

impl<'i, R> Sync for Pair<'i, R>

impl<'i, R> Unpin for Pair<'i, R>

impl<'i, R> UnsafeUnpin for Pair<'i, R>

impl<'i, R> UnwindSafe for Pair<'i, R>

impl<'i, R: $crate::clone::Clone> Clone for Pair<'i, R>

fn clone(self: &Self) -> Pair<'i, R>

impl<'i, R: Eq> Eq for Pair<'i, R>

impl<'i, R: Hash> Hash for Pair<'i, R>

fn hash<H: Hasher>(self: &Self, state: &mut H)

impl<'i, R: PartialEq> PartialEq for Pair<'i, R>

fn eq(self: &Self, other: &Pair<'i, R>) -> bool

impl<'i, R: RuleType> Debug for Pair<'i, R>

fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result

impl<'i, R: RuleType> Display for Pair<'i, R>

fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result

impl<T> Any for Pair<'i, R>

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for Pair<'i, R>

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for Pair<'i, R>

fn borrow_mut(self: &mut Self) -> &mut T

impl<T> CloneToUninit for Pair<'i, R>

unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)

impl<T> From for Pair<'i, R>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> ToOwned for Pair<'i, R>

fn to_owned(self: &Self) -> T
fn clone_into(self: &Self, target: &mut T)

impl<T> ToString for Pair<'i, R>

fn to_string(self: &Self) -> String

impl<T, U> Into for Pair<'i, R>

fn into(self: Self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom for Pair<'i, R>

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto for Pair<'i, R>

fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>