Skip to main content

JValue

Enum JValue 

Source
pub enum JValue {
    Null,
    Bool(bool),
    Number(f64),
    String(Rc<str>),
    Array(Rc<Vec<JValue>>),
    Object(Rc<IndexMap<String, JValue>>),
    Undefined,
    Lambda {
        lambda_id: Rc<str>,
        params: Rc<Vec<String>>,
        name: Option<Rc<str>>,
        signature: Option<Rc<str>>,
    },
    Builtin {
        name: Rc<str>,
    },
    Regex {
        pattern: Rc<str>,
        flags: Rc<str>,
    },
}
Expand description

A JSON-like value with O(1) clone semantics via Rc-wrapping.

Standard JSON types (Array, Object, String) are wrapped in Rc for cheap cloning. Internal types (Undefined, Lambda, Builtin, Regex) are first-class variants instead of tagged objects with hash-map lookups.

Variants§

§

Null

§

Bool(bool)

§

Number(f64)

§

String(Rc<str>)

§

Array(Rc<Vec<JValue>>)

§

Object(Rc<IndexMap<String, JValue>>)

§

Undefined

§

Lambda

Fields

§lambda_id: Rc<str>
§params: Rc<Vec<String>>
§name: Option<Rc<str>>
§signature: Option<Rc<str>>
§

Builtin

Fields

§name: Rc<str>
§

Regex

Fields

§pattern: Rc<str>
§flags: Rc<str>

Implementations§

Source§

impl JValue

Source

pub fn is_null(&self) -> bool

Source

pub fn is_undefined(&self) -> bool

Source

pub fn is_bool(&self) -> bool

Source

pub fn is_number(&self) -> bool

Source

pub fn is_string(&self) -> bool

Source

pub fn is_array(&self) -> bool

Source

pub fn is_object(&self) -> bool

Source

pub fn is_lambda(&self) -> bool

Source

pub fn is_builtin(&self) -> bool

Source

pub fn is_function(&self) -> bool

Source

pub fn is_regex(&self) -> bool

Source§

impl JValue

Source

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

Source

pub fn as_i64(&self) -> Option<i64>

Source

pub fn as_str(&self) -> Option<&str>

Source

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

Source

pub fn as_array(&self) -> Option<&Vec<JValue>>

Source

pub fn as_object(&self) -> Option<&IndexMap<String, JValue>>

Source

pub fn as_array_mut(&mut self) -> Option<&mut Vec<JValue>>

Get a mutable reference to the inner Vec, cloning if shared (Rc::make_mut).

Source

pub fn as_object_mut(&mut self) -> Option<&mut IndexMap<String, JValue>>

Get a mutable reference to the inner IndexMap, cloning if shared (Rc::make_mut).

Source

pub fn as_rc_str(&self) -> Option<&Rc<str>>

Get a reference to the Rc for the string variant.

Source

pub fn get(&self, key: &str) -> Option<&JValue>

Index into an object by key.

Source

pub fn get_index(&self, index: usize) -> Option<&JValue>

Index into an array by position.

Source§

impl JValue

Source

pub fn from_i64(n: i64) -> Self

Source

pub fn from_f64(n: f64) -> Self

Source

pub fn string(s: impl Into<Rc<str>>) -> Self

Source

pub fn array(v: Vec<JValue>) -> Self

Source

pub fn object(m: IndexMap<String, JValue>) -> Self

Source

pub fn lambda( lambda_id: impl Into<Rc<str>>, params: Vec<String>, name: Option<impl Into<Rc<str>>>, signature: Option<impl Into<Rc<str>>>, ) -> Self

Source

pub fn builtin(name: impl Into<Rc<str>>) -> Self

Source

pub fn regex(pattern: impl Into<Rc<str>>, flags: impl Into<Rc<str>>) -> Self

Source§

impl JValue

Source

pub fn to_json_string(&self) -> Result<String, Error>

Serialize to a JSON string.

Source

pub fn to_json_string_pretty(&self) -> Result<String, Error>

Serialize to a pretty-printed JSON string.

Source

pub fn from_json_str(s: &str) -> Result<JValue, Error>

Parse a JSON string into a JValue (single-pass, no intermediate serde_json::Value).

When the simd feature is enabled, uses simd-json for 2-4x faster parsing on CPUs with SIMD support (SSE4.2/AVX2/NEON). Falls back to serde_json otherwise.

Trait Implementations§

Source§

impl Clone for JValue

Source§

fn clone(&self) -> JValue

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for JValue

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for JValue

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for JValue

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<&JValue> for Value

Source§

fn from(v: &JValue) -> Self

Converts to this type from the input type.
Source§

impl From<&str> for JValue

Source§

fn from(s: &str) -> Self

Converts to this type from the input type.
Source§

impl From<IndexMap<String, JValue>> for JValue

Source§

fn from(m: IndexMap<String, JValue>) -> Self

Converts to this type from the input type.
Source§

impl From<Rc<str>> for JValue

Source§

fn from(s: Rc<str>) -> Self

Converts to this type from the input type.
Source§

impl From<String> for JValue

Source§

fn from(s: String) -> Self

Converts to this type from the input type.
Source§

impl From<Value> for JValue

Source§

fn from(v: Value) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<JValue>> for JValue

Source§

fn from(v: Vec<JValue>) -> Self

Converts to this type from the input type.
Source§

impl From<bool> for JValue

Source§

fn from(b: bool) -> Self

Converts to this type from the input type.
Source§

impl From<f64> for JValue

Source§

fn from(n: f64) -> Self

Converts to this type from the input type.
Source§

impl From<i32> for JValue

Source§

fn from(n: i32) -> Self

Converts to this type from the input type.
Source§

impl From<i64> for JValue

Source§

fn from(n: i64) -> Self

Converts to this type from the input type.
Source§

impl From<u64> for JValue

Source§

fn from(n: u64) -> Self

Converts to this type from the input type.
Source§

impl From<usize> for JValue

Source§

fn from(n: usize) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for JValue

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for JValue

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,