Skip to main content

Source

Trait Source 

Source
pub trait Source {
    type Volatility: Volatility;

    const UTF8: bool;
    const INSITU: bool;
    const NULL_PADDED: bool;

    // Required methods
    fn ptr(&mut self, offset: usize) -> *const u8;
    fn ptr_mut(&mut self, offset: usize) -> *mut u8;
    fn trim(&mut self, until: usize);
    fn len(&mut self) -> usize;
}
Expand description

Trait representing a source of JSON data for parsing.

This trait abstracts over different input types, allowing the parser to work with strings, byte slices, and streaming readers uniformly.

Required Associated Constants§

Source

const UTF8: bool

Whether the source is guaranteed to be valid UTF-8.

When false, the parser will validate UTF-8 encoding for JSON string values.

Note: Validation is limited to strings only, as invalid UTF-8 elsewhere in the JSON will be rejected as an unexpected token during parsing.

Source

const INSITU: bool

Whether the source allows in-situ (in-place) parsing.

In-situ parsing modifies the source data directly to parse strings. Requires the source to be non volatile as well.

Source

const NULL_PADDED: bool

Whether the source is 64 null bytes padded at the end. Allows the parser to skip bounds checking.

§Safety

The source must be non volatile. As the parser will store and use the pointer as index.

Required Associated Types§

Source

type Volatility: Volatility

The volatility of the source.

Required Methods§

Source

fn ptr(&mut self, offset: usize) -> *const u8

Returns a pointer at the given offset.

§Safety

The parser ensures the offset is within bounds by checking len() beforehand. Implementations must not panic.

Source

fn ptr_mut(&mut self, offset: usize) -> *mut u8

Returns a mutable pointer to the byte at the given offset.

This method is used for in-situ parsing. Implementations may return a null pointer or use unimplemented!()/unreachable() if INSITU is false. The parser only calls this method when in-situ parsing conditions are met.

§Safety

The parser ensures the offset is within bounds by checking len() beforehand. Implementations must not panic.

Source

fn trim(&mut self, until: usize)

Signal to discard data up to the given offset (exclusive).

This method is only called for volatile sources to free memory as data is consumed.

Source

fn len(&mut self) -> usize

Returns the current length of available source data in bytes.

The parser requires at least 64 bytes of data to be available during parsing, otherwise it may give false EOF-related errors.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl Source for &str

Source§

const UTF8: bool = true

Source§

const INSITU: bool = false

Source§

const NULL_PADDED: bool = false

Source§

type Volatility = NonVolatile

Source§

fn ptr(&mut self, offset: usize) -> *const u8

Source§

fn ptr_mut(&mut self, _: usize) -> *mut u8

Source§

fn trim(&mut self, _: usize)

Source§

fn len(&mut self) -> usize

Source§

impl Source for &mut str

Source§

const UTF8: bool = true

Source§

const INSITU: bool = true

Source§

const NULL_PADDED: bool = false

Source§

type Volatility = NonVolatile

Source§

fn ptr(&mut self, offset: usize) -> *const u8

Source§

fn ptr_mut(&mut self, offset: usize) -> *mut u8

Source§

fn trim(&mut self, _: usize)

Source§

fn len(&mut self) -> usize

Implementors§

Source§

impl Source for &NullPadded

Source§

impl Source for &mut NullPadded

Source§

impl<const UTF8: bool, R: Read> Source for Reader<R, UTF8>