Skip to main content

JsonValueRef

Struct JsonValueRef 

Source
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§

Source§

impl<'a> JsonValueRef<'a>

Source

pub const fn new(value: &'a Value) -> Self

Borrows a JSON tree without copying, traversing, or admitting it to a budget.

§Parameters
  • value - Tree that must remain alive for the lifetime of this view.
§Returns

A read-only view tied to the supplied borrow. Construction does not allocate.

Source

pub const fn as_value(self) -> &'a Value

Returns the borrowed JSON value, preserving its original owner lifetime.

Consuming this view does not extend the lifetime of the underlying tree.

§Returns

The JSON tree borrowed by this view.

Trait Implementations§

Source§

impl<'a> Clone for JsonValueRef<'a>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Copy for JsonValueRef<'a>

Source§

impl Debug for JsonValueRef<'_>

Source§

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

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

impl Eq for JsonValueRef<'_>

Source§

impl<'a, 'b> PartialEq<JsonValueRef<'b>> for JsonValueRef<'a>

Source§

fn eq(&self, other: &JsonValueRef<'b>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for JsonValueRef<'_>

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for JsonValueRef<'a>

§

impl<'a> RefUnwindSafe for JsonValueRef<'a>

§

impl<'a> Send for JsonValueRef<'a>

§

impl<'a> Sync for JsonValueRef<'a>

§

impl<'a> Unpin for JsonValueRef<'a>

§

impl<'a> UnsafeUnpin for JsonValueRef<'a>

§

impl<'a> UnwindSafe for JsonValueRef<'a>

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<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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.