Skip to main content

Val

Enum Val 

Source
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

Source

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.

Source

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

Source

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

Source

pub fn get_index(&self, i: i64) -> Val

O(1) index — returns a clone of the element (cheap: Arc bump for Arr/Obj).

Source

pub fn is_null(&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 arr_len(&self) -> Option<usize>

Array length — also works on columnar variants.

Source

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

Source

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

Source

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

Source

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

Source

pub fn as_array(&self) -> Option<&[Val]>

Source

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.

Source

pub fn into_arr(self) -> Val

Force-materialize a columnar variant to Val::Arr. No-op for Arr.

Source

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

Source

pub fn as_object(&self) -> Option<&IndexMap<Arc<str>, Val>>

Source

pub fn as_object_mut(&mut self) -> Option<&mut IndexMap<Arc<str>, Val>>

Source

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

Read-only get (serde_json compat shim).

Source

pub fn type_name(&self) -> &'static str

Source

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

Source

pub fn into_map(self) -> Option<IndexMap<Arc<str>, Val>>

Consume self and produce a mutable map (clone only if shared).

Source

pub fn arr(v: Vec<Val>) -> Self

Build a Val::Arr from a Vec without an extra allocation.

Source

pub fn int_vec(v: Vec<i64>) -> Self

Build a columnar Val::IntVec from a Vec<i64>.

Source

pub fn float_vec(v: Vec<f64>) -> Self

Build a columnar Val::FloatVec from a Vec<f64>.

Source

pub fn str_vec(v: Vec<Arc<str>>) -> Self

Build a columnar Val::StrVec from a Vec<Arc<str>>.

Source

pub fn obj(m: IndexMap<Arc<str>, Val>) -> Self

Build a Val::Obj from an IndexMap without an extra allocation.

Source

pub fn key(s: &str) -> Arc<str>

Intern a string key.

Source§

impl Val

Source

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.

Source

pub fn write_json<W: Write>(&self, w: W) -> Result<()>

Stream self as JSON into an io::Write sink.

Source

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.

Source

pub fn from_json_slice(b: &[u8]) -> Result<Val>

Trait Implementations§

Source§

impl Clone for Val

Source§

fn clone(&self) -> Val

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 Val

Source§

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

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

impl<'de> Deserialize<'de> for Val

Source§

fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Val, D::Error>

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

impl Display for Val

Source§

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

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

impl From<&Value> for Val

Source§

fn from(v: &Value) -> Self

Converts to this type from the input type.
Source§

impl From<Val> for Value

Source§

fn from(v: Val) -> Self

Converts to this type from the input type.
Source§

impl Hash for Val

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Val

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 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> 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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,