TokenSource

Trait TokenSource 

Source
pub trait TokenSource<'input> {
    // Required methods
    fn next_token(&mut self) -> Result<SpannedAdapterToken<'input>, JsonError>;
    fn skip(&mut self) -> Result<Span, JsonError>;

    // Provided methods
    fn input_bytes(&self) -> Option<&'input [u8]> { ... }
    fn at_offset(&self, offset: usize) -> Option<Self>
       where Self: Sized { ... }
}
Expand description

Trait for token sources that can be used by the deserializer.

This trait abstracts over both:

  • SliceAdapter<'input> implements TokenSource<'input> - can borrow from input
  • StreamingAdapter implements TokenSource<'static> - always owned

The lifetime parameter 'input is the lifetime of the input data, NOT the lifetime of self. This is why we don’t need GATs.

Required Methods§

Source

fn next_token(&mut self) -> Result<SpannedAdapterToken<'input>, JsonError>

Get the next token.

Source

fn skip(&mut self) -> Result<Span, JsonError>

Skip a JSON value without fully decoding it. Returns the span of the skipped value.

Provided Methods§

Source

fn input_bytes(&self) -> Option<&'input [u8]>

Get the raw input bytes, if available.

Returns Some for slice-based adapters, None for streaming. Used for features that need direct input access (RawJson, flatten replay).

Source

fn at_offset(&self, offset: usize) -> Option<Self>
where Self: Sized,

Create a new adapter starting from the given offset in the input.

Returns Some for slice-based adapters, None for streaming. Used for flatten replay.

Implementors§

Source§

impl<'input, const BORROW: bool> TokenSource<'input> for SliceAdapter<'input, BORROW>