Skip to main content

JSONValue

Enum JSONValue 

Source
pub enum JSONValue<'a> {
    Null,
    Boolean(bool),
    Number(f64),
    String(AtomBytes),
    Array(&'a [&'a JSONValue<'a>]),
    Object(&'a JSONHiddenClass<'a>, &'a [&'a JSONValue<'a>]),
}
Expand description

The base type for all JSON values (JSONParser.h:49). &'a JSONValue<'a> IS the C++ JSONValue*: nodes live in a bumpalo arena; the variant replaces the kind tag + LLVM RTTI; arena identity gives pointer equality.

Variants§

§

Null

null. A singleton within a JSONFactory.

§

Boolean(bool)

true or false. Two singletons within a JSONFactory.

§

Number(f64)

A number, already converted to f64. Uniqued by bit pattern, so -0.0 and 0.0 are distinct nodes.

§

String(AtomBytes)

A string, interned in the AtomTable and uniqued by that handle.

§

Array(&'a [&'a JSONValue<'a>])

An array, as an arena slice of its elements in source order.

§

Object(&'a JSONHiddenClass<'a>, &'a [&'a JSONValue<'a>])

An object: the hidden class holding the sorted key names, plus the values in the same order as JSONHiddenClass::keys.

Implementations§

Source§

impl<'a> JSONValue<'a>

Source

pub fn kind(&self) -> JSONKind

Returns the JSONKind tag for this value.

Source

pub fn as_number(&self) -> Option<f64>

Returns Some(f) if this is a Number, else None.

Source

pub fn as_boolean(&self) -> Option<bool>

Returns Some(b) if this is a Boolean, else None.

Source

pub fn as_string(&self) -> Option<AtomBytes>

Returns the interned handle (resolve bytes via the AtomTable).

Source

pub fn as_array(&self) -> Option<ArrayView<'a>>

Returns an ArrayView if this is an Array, else None.

Source

pub fn as_object(&self) -> Option<ObjectView<'a>>

Returns an ObjectView if this is an Object, else None.

Source

pub fn emit_into(&self, emitter: &mut JSONEmitter<'_>, atoms: &AtomTable)

Port of JSONValue::emitInto (JSONParser.cpp:39). atoms resolves interned string handles to bytes. String handles store WTF-8 bytes (surrogate-encoded astral chars / lone surrogates are valid), which are decoded to UTF-16 for emission, matching C++ primitiveEmitString via decodeUTF8<true> (surrogate-tolerant). Plain valid UTF-8 input also works correctly via the same path.

Auto Trait Implementations§

§

impl<'a> Freeze for JSONValue<'a>

§

impl<'a> RefUnwindSafe for JSONValue<'a>

§

impl<'a> Send for JSONValue<'a>

§

impl<'a> Sync for JSONValue<'a>

§

impl<'a> Unpin for JSONValue<'a>

§

impl<'a> UnsafeUnpin for JSONValue<'a>

§

impl<'a> UnwindSafe for JSONValue<'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.