Skip to main content

Parser

Struct Parser 

Source
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

Source

pub fn new(max_capacity: usize) -> Self

Create a parser that can handle documents up to max_capacity bytes.

Source

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.

Source

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.

Source

pub fn parse_bytes(&mut self, json: &[u8]) -> Result<TapeRef<'_>>

Parse a JSON byte slice, automatically adding the required padding.

Source

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.

Source

pub fn tape_ref(&self) -> TapeRef<'_>

Returns a reference to the current tape.

Returns an empty tape before parsing or after a failed parse.

Source

pub fn parse_to_value(&mut self, json: &str) -> Result<Value<'_>>

Parse a JSON string and return a zero-copy Value.

Source

pub fn parse_bytes_to_value(&mut self, json: &[u8]) -> Result<Value<'_>>

Parse a JSON byte slice and return a zero-copy Value.

Trait Implementations§

Source§

impl Default for Parser

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.