pub struct VacantEntry<'a> { /* private fields */ }
Expand description
A view into a vacant entry in a Object
.
Implementations§
Source§impl<'a> VacantEntry<'a>
impl<'a> VacantEntry<'a>
Sourcepub fn insert<T: Into<Value>>(self, val: T) -> &'a mut Value
pub fn insert<T: Into<Value>>(self, val: T) -> &'a mut Value
Insert a value into the vacant entry and return a mutable reference to it.
§Examples
use sonic_rs::{json, object, value::object::Entry};
let mut obj = object! {};
if let Entry::Vacant(entry) = obj.entry(&"hello") {
assert_eq!(entry.insert(1), &1);
}
if let Entry::Vacant(entry) = obj.entry(&"world") {
assert_eq!(entry.insert(json!("woo").clone()), "woo");
}
assert_eq!(obj.get(&"hello").unwrap(), 1);
assert_eq!(obj.get(&"world").unwrap(), "woo");
Auto Trait Implementations§
impl<'a> Freeze for VacantEntry<'a>
impl<'a> !RefUnwindSafe for VacantEntry<'a>
impl<'a> Send for VacantEntry<'a>
impl<'a> Sync for VacantEntry<'a>
impl<'a> Unpin for VacantEntry<'a>
impl<'a> !UnwindSafe for VacantEntry<'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