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_sizebytes 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>
impl<'input, const BORROW: bool> SliceAdapter<'input, BORROW>
Sourcepub fn new(input: &'input [u8]) -> Self
pub fn new(input: &'input [u8]) -> Self
Create a new adapter with the default chunk size (4 bytes).
Sourcepub fn with_chunk_size(input: &'input [u8], chunk_size: usize) -> Self
pub fn with_chunk_size(input: &'input [u8], chunk_size: usize) -> Self
Create a new adapter with a custom chunk size.
Sourcepub fn next_token(
&mut self,
) -> Result<SpannedAdapterToken<'input>, AdapterError>
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.
Sourcepub fn skip(&mut self) -> Result<Span, AdapterError>
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.
Trait Implementations§
Source§impl<'input, const BORROW: bool> TokenSource<'input> for SliceAdapter<'input, BORROW>
impl<'input, const BORROW: bool> TokenSource<'input> for SliceAdapter<'input, BORROW>
Source§fn next_token(&mut self) -> Result<SpannedAdapterToken<'input>, JsonError>
fn next_token(&mut self) -> Result<SpannedAdapterToken<'input>, JsonError>
Get the next token.
Source§fn skip(&mut self) -> Result<Span, JsonError>
fn skip(&mut self) -> Result<Span, JsonError>
Skip a JSON value without fully decoding it.
Returns the span of the skipped value.
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more