Skip to main content

Entry

Enum Entry 

Source
pub enum Entry<'o, 'a> {
    Occupied(OccupiedEntry<'o, 'a>),
    Vacant(VacantEntry<'o, 'a>),
}
Expand description

One member of an Object, there or not; from Object::entry.

Variants§

§

Occupied(OccupiedEntry<'o, 'a>)

The object has a member with the key (the first, if several).

§

Vacant(VacantEntry<'o, 'a>)

It does not.

Implementations§

Source§

impl<'o, 'a> Entry<'o, 'a>

Source

pub fn or_insert(self, default: impl Into<Value<'a>>) -> &'o mut Value<'a>

The member’s value, inserting default first if it is missing.

§Examples
let mut o = jsonx_lib::Object::new();
o.entry("list").or_insert(jsonx_lib::json!([])).as_array_mut().unwrap().push(1.into());
assert_eq!(o["list"][0], 1);
Source

pub fn or_insert_with( self, default: impl FnOnce() -> Value<'a>, ) -> &'o mut Value<'a>

The member’s value, inserting what default makes first if it is missing.

§Examples
let mut o = jsonx_lib::Object::new();
assert!(o.entry("k").or_insert_with(|| "made".into()) == "made");
Source

pub fn or_default(self) -> &'o mut Value<'a>

The member’s value, inserting null first if it is missing.

§Examples
let mut o = jsonx_lib::Object::new();
assert!(o.entry("k").or_default().is_null());
assert_eq!(o.len(), 1);
Source

pub fn and_modify(self, change: impl FnOnce(&mut Value<'a>)) -> Self

Runs change on the value if the member is there.

§Examples
let mut v = jsonx_lib::json!({ "n": 1 });
let o = v.as_object_mut().unwrap();
o.entry("n").and_modify(|n| *n = 2.into()).or_insert(0);
o.entry("m").and_modify(|n| *n = 2.into()).or_insert(0);
assert_eq!(v.to_string(), r#"{"n":2,"m":0}"#);
Source

pub fn key(&self) -> &str

The member’s key.

§Examples
assert_eq!(jsonx_lib::Object::new().entry("k").key(), "k");

Trait Implementations§

Source§

impl<'o, 'a> Debug for Entry<'o, 'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'o, 'a> !UnwindSafe for Entry<'o, 'a>

§

impl<'o, 'a> Forget for Entry<'o, 'a>

§

impl<'o, 'a> Freeze for Entry<'o, 'a>

§

impl<'o, 'a> Move for Entry<'o, 'a>

§

impl<'o, 'a> RefUnwindSafe for Entry<'o, 'a>

§

impl<'o, 'a> Send for Entry<'o, 'a>

§

impl<'o, 'a> Sync for Entry<'o, 'a>

§

impl<'o, 'a> Unpin for Entry<'o, 'a>

§

impl<'o, 'a> UnsafeUnpin for Entry<'o, '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>,

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.