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§
Sourceconst UTF8: bool
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.
Sourceconst INSITU: bool
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.
Sourceconst NULL_PADDED: bool
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§
Sourcetype Volatility: Volatility
type Volatility: Volatility
The volatility of the source.
Required Methods§
Sourcefn ptr(&mut self, offset: usize) -> *const u8
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.
Sourcefn ptr_mut(&mut self, offset: usize) -> *mut u8
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.
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.