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>
impl<'o, 'a> Entry<'o, 'a>
Sourcepub fn or_insert(self, default: impl Into<Value<'a>>) -> &'o mut Value<'a>
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);Sourcepub fn or_insert_with(
self,
default: impl FnOnce() -> Value<'a>,
) -> &'o mut Value<'a>
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");Sourcepub fn or_default(self) -> &'o mut Value<'a>
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);Sourcepub fn and_modify(self, change: impl FnOnce(&mut Value<'a>)) -> Self
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}"#);Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more