pub struct Parser { /* private fields */ }Expand description
A simdjson DOM parser.
The parser owns an internal buffer. After calling one of the parse*
methods the tape and string buffer remain valid until the next parse call.
§Example
use simdjson_rust::dom::Parser;
let mut parser = Parser::default();
let value = parser.parse_str(r#"{"hello": "world"}"#).unwrap();
println!("{value:?}");Implementations§
Source§impl Parser
impl Parser
Sourcepub fn new(max_capacity: usize) -> Self
pub fn new(max_capacity: usize) -> Self
Create a parser that can handle documents up to max_capacity bytes.
Sourcepub unsafe fn parse_bytes_with_padding(
&mut self,
json: &[u8],
) -> Result<TapeRef<'_>>
pub unsafe fn parse_bytes_with_padding( &mut self, json: &[u8], ) -> Result<TapeRef<'_>>
Parse a JSON byte slice.
The slice must have at least SIMDJSON_PADDING bytes of extra
capacity beyond its length. Use parse_str or
parse_padded for convenience variants that
handle padding automatically.
§Errors
Returns Error::SimdJson if the parser rejects the input.
§Safety
The allocation must contain at least SIMDJSON_PADDING initialized,
readable bytes after the slice, valid throughout this call.
Sourcepub fn parse_str(&mut self, json: &str) -> Result<TapeRef<'_>>
pub fn parse_str(&mut self, json: &str) -> Result<TapeRef<'_>>
Parse a JSON string, automatically adding the required padding.
The padding is added on a private copy of the string, so the original
json argument does not need to be mutable.
Sourcepub fn parse_bytes(&mut self, json: &[u8]) -> Result<TapeRef<'_>>
pub fn parse_bytes(&mut self, json: &[u8]) -> Result<TapeRef<'_>>
Parse a JSON byte slice, automatically adding the required padding.
Sourcepub fn parse_padded(&mut self, json: &mut String) -> Result<TapeRef<'_>>
pub fn parse_padded(&mut self, json: &mut String) -> Result<TapeRef<'_>>
Parse a JSON string that is already padded (has >= SIMDJSON_PADDING
bytes of extra space in its allocation).
The string must have s.capacity() >= s.len() + SIMDJSON_PADDING.
Sourcepub fn tape_ref(&self) -> TapeRef<'_>
pub fn tape_ref(&self) -> TapeRef<'_>
Returns a reference to the current tape.
Returns an empty tape before parsing or after a failed parse.
Sourcepub fn parse_to_value(&mut self, json: &str) -> Result<Value<'_>>
pub fn parse_to_value(&mut self, json: &str) -> Result<Value<'_>>
Parse a JSON string and return a zero-copy Value.
Sourcepub fn parse_bytes_to_value(&mut self, json: &[u8]) -> Result<Value<'_>>
pub fn parse_bytes_to_value(&mut self, json: &[u8]) -> Result<Value<'_>>
Parse a JSON byte slice and return a zero-copy Value.