pub struct JsonStr { /* private fields */ }Expand description
A JSON string span — a (start, end) pair into the original input.
Materializing into a real &str requires the original input slice.
Stored as two u32s instead of a fat &[u8] so the parent Event
fits in 16 bytes (one xmm register), eliminating the per-event memory
shuffles that dominated typed parsing in profiling.
Implementations§
Source§impl JsonStr
impl JsonStr
Sourcepub const fn has_escapes(&self) -> bool
pub const fn has_escapes(&self) -> bool
true iff the lexer saw a \ in the string. When false, the raw
bytes are already valid UTF-8 (the lexer validated them inline) and
can be turned into &str for free.
pub const fn start(&self) -> u32
pub const fn end(&self) -> u32
Sourcepub fn raw_bytes<'input>(&self, input: &'input [u8]) -> Option<&'input [u8]>
pub fn raw_bytes<'input>(&self, input: &'input [u8]) -> Option<&'input [u8]>
Raw bytes between (but not including) the quotes, taken from input.
Caller must pass the same input the parser was constructed with;
otherwise the indices are meaningless. Returns None if the input
is shorter than the recorded range (only happens if the caller
passes a different/truncated buffer).
Sourcepub fn as_str<'input>(&self, input: &'input [u8]) -> Option<&'input str>
pub fn as_str<'input>(&self, input: &'input [u8]) -> Option<&'input str>
The string as &str when it contains no escapes. Skips re-validation:
the parser already ensured the bytes are valid UTF-8.
Returns None when the string had escapes (caller must decode into
a buffer) or when input doesn’t cover the recorded range.