pub struct SliceParser<'a, 'b, C: BitStackConfig = DefaultConfig> { /* private fields */ }Expand description
A pull parser that parses JSON from a slice.
Generic over BitStack storage type for configurable nesting depth.
Implementations§
Source§impl<'a> SliceParser<'a, '_, DefaultConfig>
Methods for the pull parser.
impl<'a> SliceParser<'a, '_, DefaultConfig>
Methods for the pull parser.
Sourcepub fn new(input: &'a str) -> Self
pub fn new(input: &'a str) -> Self
Creates a new parser for the given JSON input.
This parser assumes no string escapes will be encountered. If escapes are found,
parsing will fail with ScratchBufferFull error.
For JSON with potential string escapes, use with_buffer() instead.
§Arguments
input- A string slice containing the JSON data to be parsed.
§Example
use picojson::SliceParser;
let parser = SliceParser::new(r#"{"name": "value"}"#);Sourcepub fn new_from_slice(input: &'a [u8]) -> Self
pub fn new_from_slice(input: &'a [u8]) -> Self
Creates a new parser from a byte slice.
Assumes no string escapes will be encountered. For JSON with escapes, use with_buffer_from_slice.
§Example
let parser = SliceParser::new_from_slice(br#"{"name": "value"}"#);Source§impl<'a, 'b> SliceParser<'a, 'b, DefaultConfig>
Constructor with scratch buffer for SliceParser using DefaultConfig
impl<'a, 'b> SliceParser<'a, 'b, DefaultConfig>
Constructor with scratch buffer for SliceParser using DefaultConfig
Sourcepub fn with_buffer(input: &'a str, scratch_buffer: &'b mut [u8]) -> Self
pub fn with_buffer(input: &'a str, scratch_buffer: &'b mut [u8]) -> Self
Creates a new parser for the given JSON input with external scratch buffer.
Use this when your JSON contains string escapes (like \n, \", \u0041) that
need to be unescaped during parsing.
§Arguments
input- A string slice containing the JSON data to be parsed.scratch_buffer- A mutable byte slice for temporary string unescaping operations. This buffer needs to be at least as long as the longest contiguous token (string, key, number) in the input.
§Example
use picojson::SliceParser;
let mut scratch = [0u8; 1024];
let parser = SliceParser::with_buffer(r#"{"msg": "Hello\nWorld"}"#, &mut scratch);Sourcepub fn with_buffer_from_slice(
input: &'a [u8],
scratch_buffer: &'b mut [u8],
) -> Self
pub fn with_buffer_from_slice( input: &'a [u8], scratch_buffer: &'b mut [u8], ) -> Self
Creates a new parser from a byte slice with a scratch buffer.
Use when JSON contains string escapes that need unescaping.
§Example
let mut scratch = [0u8; 1024];
let parser = SliceParser::with_buffer_from_slice(br#"{"msg": "Hello\nWorld"}"#, &mut scratch);Source§impl<'a, 'b, C: BitStackConfig> SliceParser<'a, 'b, C>
Generic constructor for SliceParser with custom configurations
impl<'a, 'b, C: BitStackConfig> SliceParser<'a, 'b, C>
Generic constructor for SliceParser with custom configurations
Sourcepub fn with_config(input: &'a str) -> Self
pub fn with_config(input: &'a str) -> Self
Creates a new parser with a custom BitStackConfig.
This parser assumes no string escapes will be encountered. If escapes are found,
parsing will fail. For JSON with escapes, use with_config_and_buffer.
Sourcepub fn with_config_from_slice(input: &'a [u8]) -> Self
pub fn with_config_from_slice(input: &'a [u8]) -> Self
Creates a new parser from a byte slice with a custom BitStackConfig.
Assumes no string escapes will be encountered. For JSON with escapes, use with_config_and_buffer_from_slice.
Sourcepub fn with_config_and_buffer(
input: &'a str,
scratch_buffer: &'b mut [u8],
) -> Self
pub fn with_config_and_buffer( input: &'a str, scratch_buffer: &'b mut [u8], ) -> Self
Creates a new parser with a custom BitStackConfig and a user-provided scratch buffer.
Use this when your JSON contains string escapes (like \n, \", \u0041).
§Arguments
input- A string slice containing the JSON data to be parsed.scratch_buffer- A mutable byte slice for temporary string unescaping operations. This buffer needs to be at least as long as the longest contiguous token (string, key, number) in the input.
Sourcepub fn with_config_and_buffer_from_slice(
input: &'a [u8],
scratch_buffer: &'b mut [u8],
) -> Self
pub fn with_config_and_buffer_from_slice( input: &'a [u8], scratch_buffer: &'b mut [u8], ) -> Self
Creates a new parser from a byte slice with a custom BitStackConfig and scratch buffer.
Use when JSON contains string escapes that need unescaping. This is the core constructor that all other constructors delegate to.
Trait Implementations§
Source§impl<'a, 'b, C: BitStackConfig> PullParser for SliceParser<'a, 'b, C>
impl<'a, 'b, C: BitStackConfig> PullParser for SliceParser<'a, 'b, C>
Source§fn next_event(&mut self) -> Result<Event<'_, '_>, ParseError>
fn next_event(&mut self) -> Result<Event<'_, '_>, ParseError>
EndDocument is returned or an error occurs.