Skip to main content

Sax

Trait Sax 

Source
pub trait Sax<'src> {
    type Output;

    // Required methods
    fn null(&mut self);
    fn bool_val(&mut self, v: bool);
    fn number(&mut self, s: &'src str);
    fn string(&mut self, s: &'src str);
    fn escaped_string(&mut self, s: &str);
    fn key(&mut self, s: &'src str);
    fn escaped_key(&mut self, s: &str);
    fn start_object(&mut self);
    fn end_object(&mut self);
    fn start_array(&mut self);
    fn end_array(&mut self);
    fn finish(self) -> Option<Self::Output>;
}
Expand description

Receives a stream of structural events as the parser walks the input.

Implement this trait to produce any output from a single pass over the JSON source. The built-in implementation used by crate::parse_to_dom produces a flat crate::dom::Dom.

A custom implementation can be driven via crate::parse_with (portable SWAR) or [crate::parse_with_zmm] (AVX-512BW assembly).

Required Associated Types§

Source

type Output

The type returned by finish.

Required Methods§

Source

fn null(&mut self)

A null literal was parsed.

Source

fn bool_val(&mut self, v: bool)

A true or false literal was parsed.

Source

fn number(&mut self, s: &'src str)

A JSON number; s is a slice of the original source string.

Source

fn string(&mut self, s: &'src str)

A JSON string value with no escape sequences; s borrows from the source.

Source

fn escaped_string(&mut self, s: &str)

A JSON string value that contained escape sequences. s is the raw slice from the source JSON, still containing backslash sequences (e.g. \n, \uXXXX). Call [crate::unescape_str] if you need the decoded text.

Source

fn key(&mut self, s: &'src str)

An object key with no escape sequences; s borrows from the source.

Source

fn escaped_key(&mut self, s: &str)

An object key that contained escape sequences. s is the raw slice from the source JSON, still containing backslash sequences. Call [crate::unescape_str] if you need the decoded text.

Source

fn start_object(&mut self)

Opening { of an object.

Source

fn end_object(&mut self)

Closing } of an object.

Source

fn start_array(&mut self)

Opening [ of an array.

Source

fn end_array(&mut self)

Closing ] of an array.

Source

fn finish(self) -> Option<Self::Output>

Called once after the last token; returns the final output or None on internal error.

Implementors§