ScanBuffer

Struct ScanBuffer 

Source
pub struct ScanBuffer { /* private fields */ }
Expand description

A refillable buffer for streaming JSON parsing.

Uses a grow-only strategy: we either reset (when all data processed) or grow (when mid-token). Never compacts/shifts data.

Implementations§

Source§

impl ScanBuffer

Source

pub fn new() -> Self

Create a new buffer with the default capacity.

Source

pub fn with_capacity(capacity: usize) -> Self

Create a new buffer with a specific capacity.

Source

pub fn from_slice(slice: &[u8]) -> Self

Create a buffer from an existing slice (for slice-based parsing).

Source

pub fn data(&self) -> &[u8]

Get the current buffer contents.

Source

pub fn is_eof(&self) -> bool

Whether the underlying reader has reached EOF.

Source

pub fn filled(&self) -> usize

How many bytes are filled.

Source

pub fn capacity(&self) -> usize

Get the buffer’s total capacity.

Source

pub fn reset(&mut self)

Reset the buffer for fresh data.

Called when all data has been processed (scanner returned Eof but reader has more). This is NOT compaction - we’re simply starting fresh because everything was consumed.

Source

pub fn grow(&mut self)

Grow the buffer to make room for more data.

Called when mid-token (NeedMore) and buffer is full. We grow rather than compact because:

  • No data copying needed
  • Scanner indices remain valid
  • Simpler logic
Source

pub fn refill<R: Read>(&mut self, reader: &mut R) -> Result<usize>

Refill the buffer from a synchronous reader.

Reads more data into the unfilled portion of the buffer. Returns the number of bytes read, or 0 if EOF.

Trait Implementations§

Source§

impl Debug for ScanBuffer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ScanBuffer

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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.