Skip to main content

JSONFactory

Struct JSONFactory 

Source
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>

Source

pub fn new(arena: &'a Bump, atoms: &'a AtomTable) -> JSONFactory<'a>

Create a new factory backed by arena and atoms.

Source

pub fn arena(&self) -> &'a Bump

Returns the arena backing this factory.

Source

pub fn atoms(&self) -> &'a AtomTable

Returns the atom table used by this factory.

Source

pub fn get_null(&self) -> &'a JSONValue<'a>

Returns the singleton null value.

Source

pub fn get_boolean(&self, v: bool) -> &'a JSONValue<'a>

Returns the singleton boolean value for v.

Source

pub fn get_string(&self, lit: AtomBytes) -> &'a JSONValue<'a>

JSONParser.cpp:79 — unique a string by its interned handle.

Source

pub fn get_string_str(&self, s: &str) -> &'a JSONValue<'a>

JSONParser.cpp:92 — intern str then unique.

Source

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).

Source

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.

Source

pub fn get_hidden_class(&self, keys: &[AtomBytes]) -> &'a JSONHiddenClass<'a>

JSONParser.cpp:109 — look up or create the shared hidden class for keys (already content-sorted).

Source

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.

Source

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.

Source

pub fn new_array(&self, values: &[&'a JSONValue<'a>]) -> &'a JSONValue<'a>

JSONParser.h:617 — create an array from values.

Auto Trait Implementations§

§

impl<'a> !Freeze for JSONFactory<'a>

§

impl<'a> !RefUnwindSafe for JSONFactory<'a>

§

impl<'a> !Send for JSONFactory<'a>

§

impl<'a> !Sync for JSONFactory<'a>

§

impl<'a> !UnwindSafe for JSONFactory<'a>

§

impl<'a> Unpin for JSONFactory<'a>

§

impl<'a> UnsafeUnpin for JSONFactory<'a>

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.