Struct Error

struct Error<R> { ... }

Parse-related error type.

Fields

variant: ErrorVariant<R>

Variant of the error

location: InputLocation

Location within the input string

line_col: LineColLocation

Line/column within the input string

Implementations

impl<R: RuleType> Error<R>

fn new_from_pos(variant: ErrorVariant<R>, pos: Position<'_>) -> Error<R>

Creates Error from ErrorVariant and Position.

Examples

# use pest::error::{Error, ErrorVariant};
# use pest::Position;
# #[allow(non_camel_case_types)]
# #[allow(dead_code)]
# #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
# enum Rule {
#     open_paren,
#     closed_paren
# }
# let input = "";
# let pos = Position::from_start(input);
let error = Error::new_from_pos(
    ErrorVariant::ParsingError {
        positives: vec![Rule::open_paren],
        negatives: vec![Rule::closed_paren],
    },
    pos
);

println!("{}", error);
fn new_from_span(variant: ErrorVariant<R>, span: Span<'_>) -> Error<R>

Creates Error from ErrorVariant and Span.

Examples

# use pest::error::{Error, ErrorVariant};
# use pest::{Position, Span};
# #[allow(non_camel_case_types)]
# #[allow(dead_code)]
# #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
# enum Rule {
#     open_paren,
#     closed_paren
# }
# let input = "";
# let start = Position::from_start(input);
# let end = start.clone();
# let span = start.span(&end);
let error = Error::new_from_span(
    ErrorVariant::ParsingError {
        positives: vec![Rule::open_paren],
        negatives: vec![Rule::closed_paren],
    },
    span
);

println!("{}", error);
fn with_path(self: Self, path: &str) -> Error<R>

Returns Error variant with path which is shown when formatted with Display.

Examples

# use pest::error::{Error, ErrorVariant};
# use pest::Position;
# #[allow(non_camel_case_types)]
# #[allow(dead_code)]
# #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
# enum Rule {
#     open_paren,
#     closed_paren
# }
# let input = "";
# let pos = Position::from_start(input);
Error::new_from_pos(
    ErrorVariant::ParsingError {
        positives: vec![Rule::open_paren],
        negatives: vec![Rule::closed_paren],
    },
    pos
).with_path("file.rs");
fn path(self: &Self) -> Option<&str>

Returns the path set using [Error::with_path()].

Examples

# use pest::error::{Error, ErrorVariant};
# use pest::Position;
# #[allow(non_camel_case_types)]
# #[allow(dead_code)]
# #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
# enum Rule {
#     open_paren,
#     closed_paren
# }
# let input = "";
# let pos = Position::from_start(input);
# let error = Error::new_from_pos(
#     ErrorVariant::ParsingError {
#         positives: vec![Rule::open_paren],
#         negatives: vec![Rule::closed_paren],
#     },
#     pos);
let error = error.with_path("file.rs");
assert_eq!(Some("file.rs"), error.path());
fn line(self: &Self) -> &str

Returns the line that the error is on.

fn renamed_rules<F>(self: Self, f: F) -> Error<R>
where
    F: FnMut(&R) -> String

Renames all Rules if this is a ParsingError. It does nothing when called on a CustomError.

Useful in order to rename verbose rules or have detailed per-Rule formatting.

Examples

# use pest::error::{Error, ErrorVariant};
# use pest::Position;
# #[allow(non_camel_case_types)]
# #[allow(dead_code)]
# #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
# enum Rule {
#     open_paren,
#     closed_paren
# }
# let input = "";
# let pos = Position::from_start(input);
Error::new_from_pos(
    ErrorVariant::ParsingError {
        positives: vec![Rule::open_paren],
        negatives: vec![Rule::closed_paren],
    },
    pos
).renamed_rules(|rule| {
    match *rule {
        Rule::open_paren => "(".to_owned(),
        Rule::closed_paren => "closed paren".to_owned()
    }
});
fn parse_attempts(self: &Self) -> Option<ParseAttempts<R>>

Get detailed information about errored rules sequence. Returns Some(results) only for ParsingError.

fn parse_attempts_error(self: &Self, input: &str, rule_to_message: &RuleToMessageFn<R>, is_whitespace: &IsWhitespaceFn) -> Option<Error<R>>

Get error message based on parsing attempts. Returns None in case self parse_attempts is None.

impl<R> Error for Error<R>

impl<R> Freeze for Error<R>

impl<R> RefUnwindSafe for Error<R>

impl<R> Send for Error<R>

impl<R> StructuralPartialEq for Error<R>

impl<R> Sync for Error<R>

impl<R> Unpin for Error<R>

impl<R> UnsafeUnpin for Error<R>

impl<R> UnwindSafe for Error<R>

impl<R: $crate::clone::Clone> Clone for Error<R>

fn clone(self: &Self) -> Error<R>

impl<R: $crate::cmp::Eq> Eq for Error<R>

impl<R: $crate::cmp::PartialEq> PartialEq for Error<R>

fn eq(self: &Self, other: &Error<R>) -> bool

impl<R: $crate::fmt::Debug> Debug for Error<R>

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

impl<R: $crate::hash::Hash> Hash for Error<R>

fn hash<__H: $crate::hash::Hasher>(self: &Self, state: &mut __H)

impl<R: RuleType> Display for Error<R>

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

impl<T> Any for Error<R>

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for Error<R>

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

impl<T> BorrowMut for Error<R>

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

impl<T> CloneToUninit for Error<R>

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

impl<T> From for Error<R>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> ToOwned for Error<R>

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

impl<T> ToString for Error<R>

fn to_string(self: &Self) -> String

impl<T, U> Into for Error<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 Error<R>

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

impl<T, U> TryInto for Error<R>

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