SliceAdapter

Struct SliceAdapter 

Source
pub struct SliceAdapter<'input, const BORROW: bool> { /* private fields */ }
Expand description

Token adapter for slice-based parsing with fixed-size windowing.

Uses a sliding window approach:

  • Scanner sees only chunk_size bytes at a time
  • On NeedMore, window grows (extends end) to include more bytes
  • On token complete, window slides (moves start) past consumed bytes
  • No data is copied - window is just a view into the original slice

The const generic BORROW controls string handling:

  • BORROW=true: strings without escapes are borrowed (Cow::Borrowed)
  • BORROW=false: all strings are owned (Cow::Owned)

Implementations§

Source§

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

Source

pub fn new(input: &'input [u8]) -> Self

Create a new adapter with the default chunk size (4 bytes).

Source

pub fn with_chunk_size(input: &'input [u8], chunk_size: usize) -> Self

Create a new adapter with a custom chunk size.

Source

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

Get the next token with decoded content.

Strings are decoded (escapes processed) and returned as Cow<str>. Numbers are parsed into appropriate numeric types.

Uses windowed scanning: on NeedMore, grows the window and retries. Spans are absolute positions in the original input.

Source

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

Skip a JSON value without decoding.

Returns the span of the skipped value (absolute positions). No string allocations occur.

Source

pub fn position(&self) -> usize

Get the current absolute position in the input.

Source

pub fn input(&self) -> &'input [u8]

Get the underlying input slice.

Trait Implementations§

Source§

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

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.
Source§

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

Get the raw input bytes, if available. Read more
Source§

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

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

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

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

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.