pub struct JSONFactory<'a> { /* private fields */ }Expand description
Owns all JSON nodes (in the arena), uniques strings/numbers, and shares
hidden classes. Port of JSONFactory (JSONParser.h:524). Accessors take
&self; the returned &'a JSONValue lives in the arena, independent of the
transient RefCell borrow, so a caller may interleave factory use with
parsing (as JSONParserTest::SmokeTest2 does).
Implementations§
Source§impl<'a> JSONFactory<'a>
impl<'a> JSONFactory<'a>
Sourcepub fn new(arena: &'a Bump, atoms: &'a AtomTable) -> JSONFactory<'a>
pub fn new(arena: &'a Bump, atoms: &'a AtomTable) -> JSONFactory<'a>
Create a new factory backed by arena and atoms.
Sourcepub fn get_boolean(&self, v: bool) -> &'a JSONValue<'a>
pub fn get_boolean(&self, v: bool) -> &'a JSONValue<'a>
Returns the singleton boolean value for v.
Sourcepub fn get_string(&self, lit: AtomBytes) -> &'a JSONValue<'a>
pub fn get_string(&self, lit: AtomBytes) -> &'a JSONValue<'a>
JSONParser.cpp:79 — unique a string by its interned handle.
Sourcepub fn get_string_str(&self, s: &str) -> &'a JSONValue<'a>
pub fn get_string_str(&self, s: &str) -> &'a JSONValue<'a>
JSONParser.cpp:92 — intern str then unique.
Sourcepub fn get_number(&self, value: f64) -> &'a JSONValue<'a>
pub fn get_number(&self, value: f64) -> &'a JSONValue<'a>
JSONParser.cpp:96 — unique a number by its bit pattern (so -0.0 != 0.0,
matching JSONNumber::Profile using DoubleToBits).
Sourcepub fn sort_props(&self, props: &mut [Prop<'a>]) -> Option<AtomBytes>
pub fn sort_props(&self, props: &mut [Prop<'a>]) -> Option<AtomBytes>
JSONParser.cpp:120 — sort props by key content; return the first duplicate key (by interned identity) if any, else None.
JSONParser.cpp:109 — look up or create the shared hidden class for keys
(already content-sorted).
Sourcepub fn new_object(&self, props: &mut [Prop<'a>]) -> Option<&'a JSONValue<'a>>
pub fn new_object(&self, props: &mut [Prop<'a>]) -> Option<&'a JSONValue<'a>>
JSONParser.cpp:138 — create an object from props. Sorts + dedups; returns None on a duplicate key.
Sourcepub fn new_object_sorted(&self, props: &[Prop<'a>]) -> Option<&'a JSONValue<'a>>
pub fn new_object_sorted(&self, props: &[Prop<'a>]) -> Option<&'a JSONValue<'a>>
JSONParser.cpp:138 with propsAreSorted=true — props already sorted and dup-checked.