pub enum Val {
Show 14 variants
Null,
Bool(bool),
Int(i64),
Float(f64),
Str(Arc<str>),
StrSlice(StrRef),
Arr(Arc<Vec<Val>>),
IntVec(Arc<Vec<i64>>),
FloatVec(Arc<Vec<f64>>),
StrVec(Arc<Vec<Arc<str>>>),
StrSliceVec(Arc<Vec<StrRef>>),
Obj(Arc<IndexMap<Arc<str>, Val>>),
ObjSmall(Arc<[(Arc<str>, Val)]>),
ObjVec(Arc<ObjVecData>),
}Variants§
Null
Bool(bool)
Int(i64)
Float(f64)
Str(Arc<str>)
StrSlice(StrRef)
Borrowed slice into a parent Arc<str> — zero-alloc view.
Produced by slice/split-first/substring to avoid a fresh heap
allocation per row. Treat identically to Str at all semantic
boundaries (display, serialize, compare, hash).
Arr(Arc<Vec<Val>>)
IntVec(Arc<Vec<i64>>)
FloatVec(Arc<Vec<f64>>)
StrVec(Arc<Vec<Arc<str>>>)
StrSliceVec(Arc<Vec<StrRef>>)
Columnar lane of borrowed-slice string views. Each element is a
StrRef (parent Arc + byte range); emitted by map-slice / split
fusions to avoid per-row Val enum tag + per-row heap allocation.
Serializes directly as JSON array of strings via ValRef.
Obj(Arc<IndexMap<Arc<str>, Val>>)
ObjSmall(Arc<[(Arc<str>, Val)]>)
Inline small object — flat (key, value) pair slice, no hashtable.
Used for per-row map({k1, k2, ..}) projections and similar hot
loops where the allocating an Arc<IndexMap> per row dominates.
Lookup is linear scan (fine for ≤8 entries); insertion-order
preserved. Promote to Obj if growth / key churn demands it.
ObjVec(Arc<ObjVecData>)
Columnar array-of-objects lane — struct-of-arrays with shared key
schema. Each row is an object with the exact same keys in the same
order; keys stored once in keys, row values in rows[i]. Used
by map({k1, k2, ..}) projections that produce a uniform-shape
array. Serialize iterates once over rows without per-row Arc
allocation or hashtable reconstruction.
Implementations§
Source§impl Val
impl Val
Sourcepub fn as_str_ref(&self) -> Option<&str>
pub fn as_str_ref(&self) -> Option<&str>
Unified borrowed &str view that works for both Val::Str and
Val::StrSlice. Returns None for non-string variants.
Sourcepub fn to_arc_str(&self) -> Option<Arc<str>>
pub fn to_arc_str(&self) -> Option<Arc<str>>
Extract an owning Arc<str> — cheap Arc bump for Val::Str /
Val::StrSlice covering the full parent, allocates a fresh
buffer for a partial StrSlice. Returns None for non-string
variants.
Source§impl Val
impl Val
Sourcepub fn get_field(&self, key: &str) -> Val
pub fn get_field(&self, key: &str) -> Val
O(1) field lookup — returns a clone of the child (cheap: Arc bump for Arr/Obj, copy for scalars).
Sourcepub fn get_index(&self, i: i64) -> Val
pub fn get_index(&self, i: i64) -> Val
O(1) index — returns a clone of the element (cheap: Arc bump for Arr/Obj).
pub fn is_null(&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
pub fn as_bool(&self) -> Option<bool>
pub fn as_i64(&self) -> Option<i64>
pub fn as_f64(&self) -> Option<f64>
pub fn as_str(&self) -> Option<&str>
pub fn as_array(&self) -> Option<&[Val]>
Sourcepub fn as_vals(&self) -> Option<Cow<'_, [Val]>>
pub fn as_vals(&self) -> Option<Cow<'_, [Val]>>
Materialize any array-like (including columnar) as a Cow<[Val]>.
Borrowed for Val::Arr; owned allocation for Val::IntVec/FloatVec.
pub fn as_array_mut(&mut self) -> Option<&mut Vec<Val>>
pub fn as_object(&self) -> Option<&IndexMap<Arc<str>, Val>>
pub fn as_object_mut(&mut self) -> Option<&mut IndexMap<Arc<str>, Val>>
pub fn type_name(&self) -> &'static str
Sourcepub fn into_vec(self) -> Option<Vec<Val>>
pub fn into_vec(self) -> Option<Vec<Val>>
Consume self and produce a mutable Vec (clone only if shared).
Columnar variants are materialized into Vec<Val>.
Sourcepub fn into_map(self) -> Option<IndexMap<Arc<str>, Val>>
pub fn into_map(self) -> Option<IndexMap<Arc<str>, Val>>
Consume self and produce a mutable map (clone only if shared).
Source§impl Val
impl Val
Sourcepub fn to_json_vec(&self) -> Vec<u8> ⓘ
pub fn to_json_vec(&self) -> Vec<u8> ⓘ
Serialise self as JSON bytes without building an intermediate
serde_json::Value tree. Preferred over serde_json::to_vec(&Value::from(val))
for Obj-heavy results.
Sourcepub fn write_json<W: Write>(&self, w: W) -> Result<()>
pub fn write_json<W: Write>(&self, w: W) -> Result<()>
Stream self as JSON into an io::Write sink.
Sourcepub fn from_json_str(s: &str) -> Result<Val>
pub fn from_json_str(s: &str) -> Result<Val>
Parse JSON text into Val directly — one pass, no intermediate
serde_json::Value tree. Preferred over the
serde_json::from_str -> serde_json::Value -> Val::from round-trip
for hot from_json paths.
pub fn from_json_slice(b: &[u8]) -> Result<Val>
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Val
impl<'de> Deserialize<'de> for Val
Source§fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Val, D::Error>
fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Val, D::Error>
impl Eq for Val
Auto Trait Implementations§
impl Freeze for Val
impl RefUnwindSafe for Val
impl Send for Val
impl Sync for Val
impl Unpin for Val
impl UnsafeUnpin for Val
impl UnwindSafe for Val
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.