pub trait ParserTrait<'input> {
// Required methods
fn peek(&mut self) -> Option<Result<&(Event<'input>, Span), ScanError>>;
fn next_event(&mut self) -> Option<Result<(Event<'input>, Span), ScanError>>;
fn load<R: SpannedEventReceiver<'input>>(
&mut self,
recv: &mut R,
multi: bool,
) -> Result<(), ScanError>;
// Provided method
fn try_load<R: TrySpannedEventReceiver<'input>>(
&mut self,
recv: &mut R,
multi: bool,
) -> Result<(), TryLoadError<R::Error>> { ... }
}Expand description
Trait extracted from Parser to support mocking and alternative implementations.
Required Methods§
Sourcefn peek(&mut self) -> Option<Result<&(Event<'input>, Span), ScanError>>
fn peek(&mut self) -> Option<Result<&(Event<'input>, Span), ScanError>>
Try to load the next event and return it, but do not consuming it from self.
Sourcefn next_event(&mut self) -> Option<Result<(Event<'input>, Span), ScanError>>
fn next_event(&mut self) -> Option<Result<(Event<'input>, Span), ScanError>>
Try to load the next event and return it, consuming it from self.
Sourcefn load<R: SpannedEventReceiver<'input>>(
&mut self,
recv: &mut R,
multi: bool,
) -> Result<(), ScanError>
fn load<R: SpannedEventReceiver<'input>>( &mut self, recv: &mut R, multi: bool, ) -> Result<(), ScanError>
Load the YAML from the stream in self, pushing events into recv.
Use this method when event handling is infallible. If receiver code can return an
application error and should stop parsing, use ParserTrait::try_load instead. If the
caller should directly control when the next event is read, use ParserTrait::next_event
or Parser’s core::iter::Iterator implementation.
§Errors
Returns ScanError when scanning or parsing the stream fails.
Provided Methods§
Sourcefn try_load<R: TrySpannedEventReceiver<'input>>(
&mut self,
recv: &mut R,
multi: bool,
) -> Result<(), TryLoadError<R::Error>>
fn try_load<R: TrySpannedEventReceiver<'input>>( &mut self, recv: &mut R, multi: bool, ) -> Result<(), TryLoadError<R::Error>>
Load the YAML from the stream in self, stopping if recv returns an error.
If multi is set to true, the parser will allow parsing of multiple YAML documents
inside the stream.
If the receiver returns an error, the parser is left positioned immediately after the event that caused the receiver error. Callers should treat the parser as partially consumed.
§Errors
Returns TryLoadError::Scan when scanning or parsing the stream fails. Returns
TryLoadError::Receiver when recv returns an error.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.