Trait winnow::error::FinishIResult
source · pub trait FinishIResult<I, O, E> {
fn finish(self) -> Result<O, E>;
fn finish_err(self) -> Result<(I, O), E>;
}
👎Deprecated since 0.4.0: Replaced with
Parser::parse
Expand description
Extension trait to convert a parser’s IResult
to a more manageable type
Required Methods§
sourcefn finish(self) -> Result<O, E>
fn finish(self) -> Result<O, E>
👎Deprecated since 0.4.0: Replaced with
Parser::parse
Converts the parser’s IResult
to a type that is more consumable by callers.
Errors if the parser is not at the end of input. See
FinishIResult::finish_err
if the remaining input is needed.
Panic
If the result is Err(ErrMode::Incomplete(_))
, this method will panic.
- Complete parsers: It will not be an issue,
Incomplete
is never used - Partial parsers:
Incomplete
will be returned if there’s not enough data for the parser to decide, and you should gather more data before parsing again. Once the parser returns eitherOk(_)
,Err(ErrMode::Backtrack(_))
orErr(ErrMode::Cut(_))
, you can get out of the parsing loop and callfinish_err()
on the parser’s result
Example
use winnow::prelude::*;
use winnow::character::hex_uint;
use winnow::error::Error;
struct Hex(u64);
fn parse(value: &str) -> Result<Hex, Error<String>> {
hex_uint.map(Hex).parse_next(value).finish().map_err(Error::into_owned)
}
sourcefn finish_err(self) -> Result<(I, O), E>
fn finish_err(self) -> Result<(I, O), E>
👎Deprecated since 0.4.0: Replaced with
Parser::parse
Converts the parser’s IResult
to a type that is more consumable by errors.
It keeps the same Ok
branch, and merges ErrMode::Backtrack
and ErrMode::Cut
into the Err
side.
Panic
If the result is Err(ErrMode::Incomplete(_))
, this method will panic as ErrMode::Incomplete
should only be set when the input is StreamIsPartial<false>
which this isn’t implemented
for.