Trait nom8::FinishIResult

source ·
pub trait FinishIResult<I, O, E> {
    // Required methods
    fn finish(self) -> Result<O, E>;
    fn finish_err(self) -> Result<(I, O), E>;
}
Expand description

Extension trait to convert a parser’s IResult to a more manageable type

Required Methods§

source

fn finish(self) -> Result<O, E>

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(Err::Incomplete(_)), this method will panic.

  • “complete” parsers: It will not be an issue, Incomplete is never used
  • “streaming” 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 either Ok(_), Err(Err::Error(_)) or Err(Err::Failure(_)), you can get out of the parsing loop and call finish_err() on the parser’s result
source

fn finish_err(self) -> Result<(I, O), E>

Converts the parser’s IResult to a type that is more consumable by errors.

It keeps the same Ok branch, and merges Err::Error and Err::Failure into the Err side.

Panic

If the result is Err(Err::Incomplete(_)), this method will panic as Err::Incomplete should only be set when the input is InputIsStreaming<false> which this isn’t implemented for.

Implementors§

source§

impl<I, O, E> FinishIResult<I, O, E> for IResult<I, O, E>where I: InputLength + IntoOutput + InputIsStreaming<false> + Clone, E: ParseError<I>,