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>
impl<T> ParseResult<T>
Sourcepub fn forward_errors(self, errors: &mut Vec<Error>) -> Result<T, Vec<Error>>
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:
ParseResult::Okis converted toOk.ParseResult::Recoverableis converted toOk. The errors are appended to the given mutableVec.ParseResult::Unrecoverableis converted toErr.
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.
Sourcepub fn is_ok(&self) -> bool
pub fn is_ok(&self) -> bool
Returns true if the result is ParseResult::Ok.
Sourcepub fn inspect_unrecoverable<F>(self, f: F) -> Self
pub fn inspect_unrecoverable<F>(self, f: F) -> Self
Calls the provided closure with a reference to the contained unrecoverable error.
This is equivalent to Result::inspect_err.
Sourcepub fn map<U, F>(self, f: F) -> ParseResult<U>where
F: FnOnce(T) -> U,
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.
Sourcepub fn or_else<F>(self, op: F) -> Selfwhere
F: FnOnce() -> Self,
pub fn or_else<F>(self, op: F) -> Selfwhere
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.