Trait rstml::recoverable::ParseRecoverable

source ·
pub trait ParseRecoverable: Sized {
    // Required method
    fn parse_recoverable(
        parser: &mut RecoverableContext,
        input: ParseStream<'_>,
    ) -> Option<Self>;
}
Expand description

Parsing interface for recoverable TokenStream parsing, analog to syn::parse::Parse but with ability to skip unexpected tokens, and more diagnostic messages.

  • If input stream can be parsed to valid, or partially valid object Option::Some should be returned.

  • If object is parsed partially one can save diagnostic message in RecoverableContext.

  • If object is failed to parse Option::None should be returned, and any message should be left in RecoverableContext.

Instead of using RecoverableContext the interface can be changed to the following:

pub trait ParseRecoverable: Sized {
    fn parse_recoverable(input: ParseStream) -> ParsingResult<Self>;
}

It would more type-safe, but because std::ops::Try is not stable, writing implementation for this trait would end with a lot of boilerplate.

Required Methods§

source

fn parse_recoverable( parser: &mut RecoverableContext, input: ParseStream<'_>, ) -> Option<Self>

Object Safety§

This trait is not object safe.

Implementors§