Struct pest::error::Error

source ·
pub struct Error<R> {
    pub variant: ErrorVariant<R>,
    pub location: InputLocation,
    pub line_col: LineColLocation,
    /* private fields */
}
Expand description

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§

source§

impl<R: RuleType> Error<R>

source

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

Creates Error from ErrorVariant and Position.

Examples
let error = Error::new_from_pos(
    ErrorVariant::ParsingError {
        positives: vec![Rule::open_paren],
        negatives: vec![Rule::closed_paren]
    },
    pos
);

println!("{}", error);
source

pub fn new_from_span(variant: ErrorVariant<R>, span: Span<'_>) -> Error<R>

Creates Error from ErrorVariant and Span.

Examples
let error = Error::new_from_span(
    ErrorVariant::ParsingError {
        positives: vec![Rule::open_paren],
        negatives: vec![Rule::closed_paren]
    },
    span
);

println!("{}", error);
source

pub fn with_path(self, path: &str) -> Error<R>

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

Examples
Error::new_from_pos(
    ErrorVariant::ParsingError {
        positives: vec![Rule::open_paren],
        negatives: vec![Rule::closed_paren]
    },
    pos
).with_path("file.rs");
source

pub fn path(&self) -> Option<&str>

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

Examples
let error = error.with_path("file.rs");
assert_eq!(Some("file.rs"), error.path());
source

pub fn line(&self) -> &str

Returns the line that the error is on.

source

pub fn renamed_rules<F>(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
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()
    }
});

Trait Implementations§

source§

impl<R: Clone> Clone for Error<R>

source§

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

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<R: Debug> Debug for Error<R>

source§

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

Formats the value using the given formatter. Read more
source§

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

source§

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

Formats the value using the given formatter. Read more
source§

impl<R> Error for Error<R>where Self: Debug + Display,

1.30.0 · source§

fn source(&self) -> Option<&(dyn Error + 'static)>

The lower-level source of this error, if any. Read more
1.0.0 · source§

fn description(&self) -> &str

👎Deprecated since 1.42.0: use the Display impl or to_string()
1.0.0 · source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type based access to context intended for error reports. Read more
source§

impl<R: Hash> Hash for Error<R>

source§

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

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<R: PartialEq> PartialEq for Error<R>

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<R: Eq> Eq for Error<R>

source§

impl<R> StructuralEq for Error<R>

source§

impl<R> StructuralPartialEq for Error<R>

Auto Trait Implementations§

§

impl<R> RefUnwindSafe for Error<R>where R: RefUnwindSafe,

§

impl<R> Send for Error<R>where R: Send,

§

impl<R> Sync for Error<R>where R: Sync,

§

impl<R> Unpin for Error<R>where R: Unpin,

§

impl<R> UnwindSafe for Error<R>where R: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

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

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

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

Performs the conversion.