API Reference - louisphilipmarcoux/rill-json GitHub Wiki
This is a detailed reference for all public items exposed by the rill-json crate.
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 implementsIterator<Item = Result<ParserEvent, ParseError>>. -
Err(ParseError): An error if the input exceeds the 10MB size limit (this check happens before parsing begins).
-
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 (trueorfalse). -
Null: Anullvalue.
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 sliceCow::Borrowed("hello")(zero allocations). - If a string has escapes (e.g.,
"a\nb"), the parser must build a new string and returnsCow::Owned("a\n".to_string()).
A native Rust representation of any valid JSON value. It is primarily used for serializing data into a JSON string.
NullBoolean(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.
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.
Methods for serializing a JsonValue instance.
-
pub fn stringify(&self) -> Result<String, fmt::Error>- Serializes the
JsonValueinto a compact, minified JSON string. - Returns
Errif theJsonValuecontainsf64::NANorf64::INFINITY, which are invalid in JSON.
- Serializes the
-
pub fn stringify_pretty(&self) -> Result<String, fmt::Error>- Serializes the
JsonValueinto a human-readable, indented ("pretty-printed") JSON string. - Returns
Errforf64::NANorf64::INFINITY.
- Serializes the
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.