Skip to main content

TokenizeScratch

Struct TokenizeScratch 

Source
pub struct TokenizeScratch {
    pub xml_buf: Vec<u8>,
    pub text_buf: String,
    /* private fields */
}
Expand description

Scratch buffer pool for tokenization to minimize allocations.

Pre-allocated buffers that can be reused across tokenization operations to avoid repeated allocations in hot paths. This is critical for embedded environments where allocation overhead must be minimized.

Fields§

§xml_buf: Vec<u8>

Buffer for XML parsing

§text_buf: String

Buffer for text accumulation and normalization

Implementations§

Source§

impl TokenizeScratch

Source

pub fn new(xml_capacity: usize, text_capacity: usize) -> Self

Create scratch buffers with specified capacities.

§Arguments
  • xml_capacity - Initial capacity for XML parsing buffer
  • text_capacity - Initial capacity for text accumulation buffer
§Example
use epub_stream::tokenizer::TokenizeScratch;

let scratch = TokenizeScratch::new(4096, 8192);
Source

pub fn embedded() -> Self

Create buffers suitable for embedded use (small, bounded).

Uses conservative buffer sizes suitable for constrained environments:

  • XML buffer: 4KB
  • Text buffer: 8KB
  • Element stack: 64 elements
Source

pub fn desktop() -> Self

Create buffers for desktop use (larger, more performant).

Uses larger buffer sizes for better performance on desktop:

  • XML buffer: 32KB
  • Text buffer: 64KB
  • Element stack: 64 elements
Source

pub fn clear(&mut self)

Clear all buffers without deallocating.

This preserves the allocated capacity while resetting the length to zero, allowing the buffers to be reused for subsequent tokenization operations without requiring new allocations.

Source

pub fn ensure_text_capacity(&mut self, min_cap: usize)

Ensure text buffer has at least the given capacity.

§Arguments
  • min_cap - Minimum capacity required

If the current capacity is less than min_cap, the buffer will be expanded to at least that capacity.

Trait Implementations§

Source§

impl Debug for TokenizeScratch

Source§

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

Formats the value using the given formatter. 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.