pub enum DataValue<'a> {
Null,
Bool(bool),
Number(NumberValue),
String(&'a str),
Array(&'a [DataValue<'a>]),
Object(&'a [(&'a str, DataValue<'a>)]),
}Expand description
Arena-allocated JSON value tree. Mirrors serde_json::Value in shape
and access surface, but every composite payload lives in a Bump.
Variants§
Null
Bool(bool)
Number(NumberValue)
String(&'a str)
Array(&'a [DataValue<'a>])
Object(&'a [(&'a str, DataValue<'a>)])
Implementations§
Source§impl DataValue<'_>
impl DataValue<'_>
Sourcepub fn write_json_into(&self, out: &mut Vec<u8>)
pub fn write_json_into(&self, out: &mut Vec<u8>)
Append the compact JSON encoding of this value to out. Useful when
you want to amortize allocation across many values into a shared buffer.
For one-shot string conversion, use the fmt::Display impl
(v.to_string() / format!("{v}") / println!("{v}")).
Sourcepub fn pretty(&self) -> Pretty<'_, DataValue<'_>>
pub fn pretty(&self) -> Pretty<'_, DataValue<'_>>
Pretty-print wrapper. format!("{}", v.pretty()) produces the same
two-space-indented layout as serde_json::to_string_pretty.
use bumpalo::Bump;
use datavalue_rs::DataValue;
let arena = Bump::new();
let v = DataValue::from_str(r#"{"a":1}"#, &arena).unwrap();
assert_eq!(v.pretty().to_string(), "{\n \"a\": 1\n}");Sourcepub fn write_json_pretty_into(&self, out: &mut Vec<u8>)
pub fn write_json_pretty_into(&self, out: &mut Vec<u8>)
Append the pretty JSON encoding of this value to out.
Source§impl<'a> DataValue<'a>
impl<'a> DataValue<'a>
Sourcepub fn to_owned(&self) -> OwnedDataValue
pub fn to_owned(&self) -> OwnedDataValue
Deep-clone this arena-bound tree into an OwnedDataValue that
no longer references the arena.
Source§impl<'a> DataValue<'a>
impl<'a> DataValue<'a>
pub fn null() -> Self
pub fn bool(b: bool) -> Self
pub fn from_i64(i: i64) -> Self
pub fn from_f64(f: f64) -> Self
pub fn from_str_in(s: &str, arena: &'a Bump) -> Self
Sourcepub fn from_borrowed_str(s: &'a str) -> Self
pub fn from_borrowed_str(s: &'a str) -> Self
Wrap a string slice that already lives in the arena (or has the required lifetime). No allocation.
pub fn is_null(&self) -> bool
pub fn is_bool(&self) -> bool
pub fn is_number(&self) -> bool
pub fn is_i64(&self) -> bool
pub fn is_f64(&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_number(&self) -> Option<&NumberValue>
pub fn as_str(&self) -> Option<&'a str>
pub fn as_array(&self) -> Option<&'a [DataValue<'a>]>
pub fn as_object(&self) -> Option<&'a [(&'a str, DataValue<'a>)]>
Sourcepub fn get<I: ValueIndex>(&self, index: I) -> Option<&DataValue<'a>>
pub fn get<I: ValueIndex>(&self, index: I) -> Option<&DataValue<'a>>
serde_json::Value::get-style lookup. Accepts &str for object
keys or usize for array indices.
Sourcepub fn len(&self) -> Option<usize>
pub fn len(&self) -> Option<usize>
Number of elements in an array / object. None for non-collections.
pub fn is_empty(&self) -> Option<bool>
Sourcepub fn members(&self) -> Iter<'_, DataValue<'a>>
pub fn members(&self) -> Iter<'_, DataValue<'a>>
Iterate array items. Returns an empty iterator if self is not an
array — same convenience pattern as json-rust’s members.
Sourcepub fn entries(&self) -> EntriesIter<'_, 'a>
pub fn entries(&self) -> EntriesIter<'_, 'a>
Iterate object entries as (key, value) pairs in insertion order.
Returns an empty iterator if self is not an object.
Sourcepub fn to_json_string(&self) -> String
pub fn to_json_string(&self) -> String
Serialise to a compact JSON string. Equivalent to format!("{self}") /
self.to_string() — provided as the conventional name people reach
for, and so callers don’t have to import std::fmt::Write.