Enum ParseResult

Source
pub enum ParseResult<T> {
    Ok(T),
    Recoverable(T, Vec<Error>),
    Unrecoverable(Vec<Error>),
}
Expand description

The result of a parsing operation.

Variants§

§

Ok(T)

Parsing was successful.

§

Recoverable(T, Vec<Error>)

An error occurred while parsing, however the parser attempted to recover and has tried to continue parsing in order to find more errors. The recovered value is returned in addition to all the errors that were found.

There are no guarantees on whether the recovered value is valid or not. Thus, it should only be used to allow the parser to continue parsing, and should not be shown to the user.

§

Unrecoverable(Vec<Error>)

An error occurred while parsing, and the parser was unable to recover. Parsing is aborted and the error are returned.

Implementations§

Source§

impl<T> ParseResult<T>

Source

pub fn forward_errors(self, errors: &mut Vec<Error>) -> Result<T, Vec<Error>>

Converts the ParseResult<T> to a Result<T, Vec<Error>>, using these rules:

This can be a convenient way to allow utilizing the [?] operator in a parsing function, while still holding onto errors that were found for later reporting.

Source

pub fn is_ok(&self) -> bool

Returns true if the result is ParseResult::Ok.

Source

pub fn inspect_unrecoverable<F>(self, f: F) -> Self
where F: FnOnce(&Vec<Error>),

Calls the provided closure with a reference to the contained unrecoverable error.

This is equivalent to Result::inspect_err.

Source

pub fn map<U, F>(self, f: F) -> ParseResult<U>
where F: FnOnce(T) -> U,

Maps a ParseResult<T> to ParseResult<U> by applying a function to a contained ParseResult::Ok or ParseResult::Recoverable value, leaving an ParseResult::Unrecoverable value untouched.

This is equivalent to Result::map.

Source

pub fn or_else<F>(self, op: F) -> Self
where F: FnOnce() -> Self,

Calls op if the result is an error, otherwise returns the Ok value of self.

This is similar to Result::or_else, but no error value is given to the closure.

Trait Implementations§

Source§

impl<T: Debug> Debug for ParseResult<T>

Source§

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

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

impl<T> From<(T, Vec<Error>)> for ParseResult<T>

Source§

fn from((value, errors): (T, Vec<Error>)) -> Self

Converts to this type from the input type.
Source§

impl<T> From<Result<(T, Vec<Error>), Vec<Error>>> for ParseResult<T>

Source§

fn from(result: Result<(T, Vec<Error>), Vec<Error>>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<Vec<Error>> for ParseResult<T>

Source§

fn from(errors: Vec<Error>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<T> Freeze for ParseResult<T>
where T: Freeze,

§

impl<T> !RefUnwindSafe for ParseResult<T>

§

impl<T> Send for ParseResult<T>
where T: Send,

§

impl<T> !Sync for ParseResult<T>

§

impl<T> Unpin for ParseResult<T>
where T: Unpin,

§

impl<T> !UnwindSafe for ParseResult<T>

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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 T
where 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.