pub struct JsonValueRef<'a> { /* private fields */ }Expand description
An immutable, borrowed view of a JSON value.
Constructing a view copies only a reference. Equality and debug formatting
use explicit work stacks, which may allocate. Serialization uses the same
stacker-backed recursive Serde bridge as
SafeJsonValue. The bridge can grow the stack for
library-side recursive calls, but the selected serializer may still impose
its own recursion limits; it does not promise an exact memory bound or
support unlimited depth. The view does not protect the borrowed tree’s
destruction when its owner is dropped.
§Examples
use qubit_json::value::{JsonValueRef, SafeJsonValue};
let owner = SafeJsonValue::new(serde_json::json!({"items": [1, 2]}));
let view = JsonValueRef::new(owner.as_value());
assert_eq!(
serde_json::to_vec(&view).unwrap(),
serde_json::to_vec(&owner).unwrap()
);The view cannot outlive its borrowed owner:
use qubit_json::value::{JsonValueRef, SafeJsonValue};
let view = {
let owner = SafeJsonValue::new(serde_json::json!([1]));
JsonValueRef::new(owner.as_value())
};
println!("{view:?}");Implementations§
Trait Implementations§
Source§impl<'a> Clone for JsonValueRef<'a>
impl<'a> Clone for JsonValueRef<'a>
impl<'a> Copy for JsonValueRef<'a>
Source§impl Debug for JsonValueRef<'_>
impl Debug for JsonValueRef<'_>
Source§fn fmt(&self, formatter: &mut Formatter<'_>) -> Result
fn fmt(&self, formatter: &mut Formatter<'_>) -> Result
Formats the referenced JSON tree using the safe recursive formatting bridge.
Formatting may allocate an explicit work stack for nested values.
§Parameters
formatter- Formatter that receives the JSON tree’s debug representation.
§Returns
Ok(()) when formatting succeeds, or the formatting error reported by
the formatter.
impl Eq for JsonValueRef<'_>
Source§impl<'a, 'b> PartialEq<JsonValueRef<'b>> for JsonValueRef<'a>
impl<'a, 'b> PartialEq<JsonValueRef<'b>> for JsonValueRef<'a>
Source§fn eq(&self, other: &JsonValueRef<'b>) -> bool
fn eq(&self, other: &JsonValueRef<'b>) -> bool
Source§impl Serialize for JsonValueRef<'_>
impl Serialize for JsonValueRef<'_>
Source§fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>where
S: Serializer,
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>where
S: Serializer,
Serializes the referenced JSON tree through the stack-growing Serde bridge.
The bridge supports library-side recursive calls, while the serializer may still impose its own recursion limits.
§Type Parameters
S- Serializer that receives the JSON tree’s serialized representation.
§Parameters
serializer- Serializer used to encode the borrowed JSON tree.
§Returns
The value produced by the serializer after encoding succeeds.
§Errors
Returns the serializer’s error if encoding the tree fails.