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
Builtin
Regex
Implementations§
Source§impl JValue
impl JValue
pub fn is_null(&self) -> bool
pub fn is_undefined(&self) -> bool
pub fn is_bool(&self) -> bool
pub fn is_number(&self) -> bool
pub fn is_string(&self) -> bool
pub fn is_array(&self) -> bool
pub fn is_object(&self) -> bool
Sourcepub fn is_lazy(&self) -> bool
pub fn is_lazy(&self) -> bool
True only for the lazy Python-dict wrapper variant (always false when
the python feature is off). Used to guard normalize_lazy calls so
hot paths pay nothing when no lazy value is involved.
pub fn is_lambda(&self) -> bool
pub fn is_builtin(&self) -> bool
pub fn is_function(&self) -> bool
pub fn is_regex(&self) -> bool
Source§impl JValue
impl JValue
pub fn as_f64(&self) -> Option<f64>
pub fn as_i64(&self) -> Option<i64>
pub fn as_str(&self) -> Option<&str>
pub fn as_bool(&self) -> Option<bool>
pub fn as_array(&self) -> Option<&Vec<JValue>>
pub fn as_object(&self) -> Option<&IndexMap<String, JValue>>
Sourcepub fn as_array_mut(&mut self) -> Option<&mut Vec<JValue>>
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§impl JValue
impl JValue
pub fn from_i64(n: i64) -> Self
pub fn from_f64(n: f64) -> Self
pub fn string(s: impl Into<Rc<str>>) -> Self
pub fn array(v: Vec<JValue>) -> Self
pub fn object(m: IndexMap<String, JValue>) -> Self
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
pub fn builtin(name: impl Into<Rc<str>>) -> Self
pub fn regex(pattern: impl Into<Rc<str>>, flags: impl Into<Rc<str>>) -> Self
Source§impl JValue
impl JValue
Sourcepub fn to_json_string(&self) -> Result<String, Error>
pub fn to_json_string(&self) -> Result<String, Error>
Serialize to a JSON string.
Sourcepub fn to_json_string_pretty(&self) -> Result<String, Error>
pub fn to_json_string_pretty(&self) -> Result<String, Error>
Serialize to a pretty-printed JSON string.
Sourcepub fn from_json_str(s: &str) -> Result<JValue, Error>
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 faster parsing on CPUs
with SIMD support (SSE4.2/AVX2/NEON). Falls back to serde_json otherwise.
simd_json::serde::from_slice allocates fresh internal scratch buffers
(Buffers::new) on every call, sized proportionally to the input - measured
as the dominant cost, large enough to make the “simd” path consistently
SLOWER than plain serde_json (worse as input grows: -26% at 189 bytes,
-29% at 180KB). Reusing those buffers across calls via
from_slice_with_buffers (thread-local, since JValue’s Rc-based design is
already single-threaded per instance) eliminates that reallocation and
brings simd-json back to consistently faster than serde_json (+5% to +22%
across the same size range, measured with benches/examples/simd_json_bench.rs).