API Reference - louisphilipmarcoux/rill-json GitHub Wiki

This is a detailed reference for all public items exposed by the rill-json crate.

pub fn parse_streaming(input: &'_ str) -> Result&lt;StreamingParser<'_;, ParseError>

This is the main entry point for the streaming parser. It takes a JSON string slice and returns an Iterator over parser events.

  • Arguments:
    • input: &'_ str: A string slice containing the JSON data to be parsed.
  • Returns:
    • Ok(StreamingParser<'_>): A struct that implements Iterator<Item = Result<ParserEvent, ParseError>>.
    • Err(ParseError): An error if the input exceeds the 10MB size limit (this check happens before parsing begins).

rust pub enum ParserEvent<'a>

This enum represents the "events" that the StreamingParser yields.

  • StartObject: The start of an object ({).
  • EndObject: The end of an object (}).
  • StartArray: The start of an array ([).
  • EndArray: The end of an array (]).
  • Key(Cow<'a, str>): An object key.
  • String(Cow<'a, str>): A string value.
  • Number(JsonNumber): A number value (e.g., 123, -0.5).
  • Boolean(bool): A boolean value (true or false).
  • Null: A null value.

Note on Cow<'a, str>: The Key and String variants use a Cow (Clone-on-Write). This is a performance optimization.

  • If a string contains no escapes (e.g., "hello"), the parser returns a borrowed slice Cow::Borrowed("hello") (zero allocations).
  • If a string has escapes (e.g., "a\nb"), the parser must build a new string and returns Cow::Owned("a\n".to_string()).

pub enum JsonValue

A native Rust representation of any valid JSON value. It is primarily used for serializing data into a JSON string.

  • Null
  • Boolean(bool)
  • Number(JsonNumber)
  • String(String)
  • Array(Vec<JsonValue>)
  • Object(BTreeMap<String, JsonValue>)

Note on BTreeMap: The Object variant uses BTreeMap to guarantee that keys are serialized in alphabetical order, ensuring deterministic output.


pub enum JsonNumber

A native Rust representation of any valid JSON number, used by ParserEvent and JsonValue. This enum stores numbers without precision loss.

  • I64(i64): Represents a signed 64-bit integer.
  • U64(u64): Represents an unsigned 64-bit integer.
  • F64(f64): Represents a 64-bit floating-point number.

impl JsonValue

Methods for serializing a JsonValue instance.

  • pub fn stringify(&self) -> Result<String, fmt::Error>
    • Serializes the JsonValue into a compact, minified JSON string.
    • Returns Err if the JsonValue contains f64::NAN or f64::INFINITY, which are invalid in JSON.
  • pub fn stringify_pretty(&self) -> Result<String, fmt::Error>
    • Serializes the JsonValue into a human-readable, indented ("pretty-printed") JSON string.
    • Returns Err for f64::NAN or f64::INFINITY.

pub struct ParseError

The error type returned by the parser.

  • pub message: String: A human-readable description of what went wrong.
  • pub line: usize: The 1-indexed line number where the error occurred.
  • pub column: usize: The 1-indexed column number where the error occurred.
⚠️ **GitHub.com Fallback** ⚠️