Struct jsonptr::Assignment

source ·
pub struct Assignment<'a> {
    pub assigned: Cow<'a, Value>,
    pub replaced: Value,
    pub created_or_mutated: Pointer,
    pub assigned_to: Pointer,
}
Expand description

The data structure returned from a successful call to assign.

Fields§

§assigned: Cow<'a, Value>

The value that was assigned.

In the event a path is created, this will be the serde_json::Value encompassing the new branch.

§replaced: Value

The value that was replaced.

Note: serde_json::Value::Null is utilized if the value did not previously exist.

§created_or_mutated: Pointer

The path which was created or replaced.

For example, if you had the json { "foo": { "bar": "baz" } } and you assigned "new_value" to "/foo/qux/quux", then created_or_mutated would be Some("/foo/qux") as "qux" is the top-level value assigned.

The resulting json would have the following structure:

{
    "foo": {
       "bar": "baz",
        "qux": {
            "quux": "new_value"
        }
    }
}

Note: if a portion of the path contains a leaf node that is to be overridden by an object or an array, then the path will be leaf that is replaced.

For example, if you had the json:

{ "foo:" "bar" }

and you assigned "new_value" to "/foo/bar/baz", then the value would be Some("/foo/bar").

§assigned_to: Pointer

A Pointer consisting of the path which was assigned.

§Example

use serde_json::json;
use jsonptr::{Pointer, Assign};
let mut data = json!({ "foo": ["zero"] });
let mut ptr = Pointer::try_from("/foo/-").unwrap();
let assignment = data.assign(&mut ptr, "one").unwrap();
assert_eq!(assignment.assigned_to, Pointer::try_from("/foo/1").unwrap());

Trait Implementations§

source§

impl<'a> Debug for Assignment<'a>

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Assignment<'a>

§

impl<'a> RefUnwindSafe for Assignment<'a>

§

impl<'a> Send for Assignment<'a>

§

impl<'a> Sync for Assignment<'a>

§

impl<'a> Unpin for Assignment<'a>

§

impl<'a> UnwindSafe for Assignment<'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> 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, U> TryFrom<U> for T
where U: Into<T>,

§

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

§

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.