pub enum OwnedDataValue {
Null,
Bool(bool),
Number(NumberValue),
String(String),
Array(Vec<OwnedDataValue>),
Object(Vec<(String, OwnedDataValue)>),
}Expand description
Heap-owned JSON value tree. Variants mirror DataValue one-for-one;
no lifetime parameter.
Variants§
Null
Bool(bool)
Number(NumberValue)
String(String)
Array(Vec<OwnedDataValue>)
Object(Vec<(String, OwnedDataValue)>)
Implementations§
Source§impl OwnedDataValue
impl OwnedDataValue
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. See
DataValue::write_json_into; this is the owned-side mirror.
Sourcepub fn pretty(&self) -> Pretty<'_, OwnedDataValue>
pub fn pretty(&self) -> Pretty<'_, OwnedDataValue>
Pretty-print wrapper; see DataValue::pretty.
use datavalue_rs::OwnedDataValue;
let v: OwnedDataValue = r#"{"a":1}"#.parse().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 OwnedDataValue
impl OwnedDataValue
Sourcepub fn from_json(input: &str) -> Result<Self, ParseError>
pub fn from_json(input: &str) -> Result<Self, ParseError>
Parse JSON into an OwnedDataValue. Internally parses into a
throwaway arena (using the fast hand-rolled parser) and deep-clones
the result out — so JSON parsing speed matches DataValue::from_str,
minus the deep-clone tail.
Also available via the std::str::FromStr trait.
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<&str>
pub fn as_array(&self) -> Option<&[OwnedDataValue]>
pub fn as_object(&self) -> Option<&[(String, OwnedDataValue)]>
Sourcepub fn get<I: OwnedValueIndex>(&self, index: I) -> Option<&OwnedDataValue>
pub fn get<I: OwnedValueIndex>(&self, index: I) -> Option<&OwnedDataValue>
serde_json::Value::get-style lookup.
pub fn len(&self) -> Option<usize>
pub fn is_empty(&self) -> Option<bool>
Sourcepub fn members(&self) -> Iter<'_, OwnedDataValue>
pub fn members(&self) -> Iter<'_, OwnedDataValue>
Iterate array items. Returns an empty iterator if self is not an
array.
Sourcepub fn entries(&self) -> OwnedEntriesIter<'_>
pub fn entries(&self) -> OwnedEntriesIter<'_>
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.
Sourcepub fn to_arena<'a>(&self, arena: &'a Bump) -> DataValue<'a>
pub fn to_arena<'a>(&self, arena: &'a Bump) -> DataValue<'a>
Borrow this owned tree into the given arena, returning a
DataValue view. Strings are arena-allocated copies.
Array/Object use alloc_slice_fill_with rather than
bumpalo::Vec::with_capacity_in + push: one pre-sized arena
allocation and a tight write loop, skipping the Vec wrapper’s
per-push capacity check and the Layout::array validation that
RawVec::allocate_in re-runs for each nested allocation.
Source§impl OwnedDataValue
impl OwnedDataValue
pub fn from_i64(i: i64) -> Self
pub fn from_f64(f: f64) -> Self
Sourcepub fn array<I, V>(items: I) -> Self
pub fn array<I, V>(items: I) -> Self
Build an OwnedDataValue::Array from anything iterable into values
that already convert into OwnedDataValue (covers all the existing
From<bool|i64|f64|String|&str|...> impls).
use datavalue_rs::OwnedDataValue;
let v = OwnedDataValue::array([1, 2, 3]);
assert_eq!(v[0].as_i64(), Some(1));
let v = OwnedDataValue::array(["a", "b"]);
assert_eq!(v[1].as_str(), Some("b"));Sourcepub fn object<I, K, V>(pairs: I) -> Self
pub fn object<I, K, V>(pairs: I) -> Self
Build an OwnedDataValue::Object from (key, value) pairs.
use datavalue_rs::OwnedDataValue;
let v = OwnedDataValue::object([("type", "NaN"), ("op", "+")]);
assert_eq!(v["type"].as_str(), Some("NaN"));
let v = OwnedDataValue::object([("count", 42)]);
assert_eq!(v["count"].as_i64(), Some(42));Trait Implementations§
Source§impl Clone for OwnedDataValue
impl Clone for OwnedDataValue
Source§fn clone(&self) -> OwnedDataValue
fn clone(&self) -> OwnedDataValue
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for OwnedDataValue
impl Debug for OwnedDataValue
Source§impl Default for OwnedDataValue
impl Default for OwnedDataValue
Source§fn default() -> OwnedDataValue
fn default() -> OwnedDataValue
Source§impl Display for OwnedDataValue
impl Display for OwnedDataValue
Source§impl<T: Into<OwnedDataValue> + Clone> From<&[T]> for OwnedDataValue
impl<T: Into<OwnedDataValue> + Clone> From<&[T]> for OwnedDataValue
Source§impl From<&String> for OwnedDataValue
impl From<&String> for OwnedDataValue
Source§impl From<&str> for OwnedDataValue
impl From<&str> for OwnedDataValue
Source§impl<T: Into<OwnedDataValue>, const N: usize> From<[T; N]> for OwnedDataValue
impl<T: Into<OwnedDataValue>, const N: usize> From<[T; N]> for OwnedDataValue
Source§impl From<()> for OwnedDataValue
impl From<()> for OwnedDataValue
Source§impl<K: Into<String>, V: Into<OwnedDataValue>> From<BTreeMap<K, V>> for OwnedDataValue
impl<K: Into<String>, V: Into<OwnedDataValue>> From<BTreeMap<K, V>> for OwnedDataValue
Source§impl<K: Into<String>, V: Into<OwnedDataValue>> From<HashMap<K, V>> for OwnedDataValue
impl<K: Into<String>, V: Into<OwnedDataValue>> From<HashMap<K, V>> for OwnedDataValue
Source§impl<T: Into<OwnedDataValue>> From<Option<T>> for OwnedDataValue
impl<T: Into<OwnedDataValue>> From<Option<T>> for OwnedDataValue
Source§impl From<String> for OwnedDataValue
impl From<String> for OwnedDataValue
Source§impl From<Vec<(String, OwnedDataValue)>> for OwnedDataValue
impl From<Vec<(String, OwnedDataValue)>> for OwnedDataValue
Source§impl<T: Into<OwnedDataValue>> From<Vec<T>> for OwnedDataValue
impl<T: Into<OwnedDataValue>> From<Vec<T>> for OwnedDataValue
Source§impl From<bool> for OwnedDataValue
impl From<bool> for OwnedDataValue
Source§impl From<f32> for OwnedDataValue
impl From<f32> for OwnedDataValue
Source§impl From<f64> for OwnedDataValue
impl From<f64> for OwnedDataValue
Source§impl From<i16> for OwnedDataValue
impl From<i16> for OwnedDataValue
Source§impl From<i32> for OwnedDataValue
impl From<i32> for OwnedDataValue
Source§impl From<i64> for OwnedDataValue
impl From<i64> for OwnedDataValue
Source§impl From<i8> for OwnedDataValue
impl From<i8> for OwnedDataValue
Source§impl From<isize> for OwnedDataValue
impl From<isize> for OwnedDataValue
Source§impl From<u16> for OwnedDataValue
impl From<u16> for OwnedDataValue
Source§impl From<u32> for OwnedDataValue
impl From<u32> for OwnedDataValue
Source§impl From<u64> for OwnedDataValue
impl From<u64> for OwnedDataValue
Source§impl From<u8> for OwnedDataValue
impl From<u8> for OwnedDataValue
Source§impl From<usize> for OwnedDataValue
impl From<usize> for OwnedDataValue
Source§impl FromStr for OwnedDataValue
impl FromStr for OwnedDataValue
Source§impl<I: OwnedValueIndex> Index<I> for OwnedDataValue
impl<I: OwnedValueIndex> Index<I> for OwnedDataValue
Source§type Output = OwnedDataValue
type Output = OwnedDataValue
Source§fn index(&self, index: I) -> &OwnedDataValue
fn index(&self, index: I) -> &OwnedDataValue
container[index]) operation. Read more