Struct ez_jsonrpc_types::map::OccupiedEntry
source · pub struct OccupiedEntry<'a, T> { /* private fields */ }
Expand description
An occupied Entry. It is part of the Entry
enum.
Implementations§
source§impl<'a, T> OccupiedEntry<'a, T>
impl<'a, T> OccupiedEntry<'a, T>
sourcepub fn key(&self) -> &String
pub fn key(&self) -> &String
Gets a reference to the key in the entry.
§Examples
use serde_json::map::Entry;
let mut map = serde_json::Map::new();
map.insert("serde".to_owned(), json!(12));
match map.entry("serde") {
Entry::Occupied(occupied) => {
assert_eq!(occupied.key(), &"serde");
}
Entry::Vacant(_) => unimplemented!(),
}
sourcepub fn get(&self) -> &T
pub fn get(&self) -> &T
Gets a reference to the value in the entry.
§Examples
use serde_json::map::Entry;
let mut map = serde_json::Map::new();
map.insert("serde".to_owned(), json!(12));
match map.entry("serde") {
Entry::Occupied(occupied) => {
assert_eq!(occupied.get(), 12);
}
Entry::Vacant(_) => unimplemented!(),
}
sourcepub fn get_mut(&mut self) -> &mut T
pub fn get_mut(&mut self) -> &mut T
Gets a mutable reference to the value in the entry.
§Examples
use serde_json::map::Entry;
let mut map = serde_json::Map::new();
map.insert("serde".to_owned(), json!([1, 2, 3]));
match map.entry("serde") {
Entry::Occupied(mut occupied) => {
occupied.get_mut().as_array_mut().unwrap().push(json!(4));
}
Entry::Vacant(_) => unimplemented!(),
}
assert_eq!(map["serde"].as_array().unwrap().len(), 4);
sourcepub fn into_mut(self) -> &'a mut T
pub fn into_mut(self) -> &'a mut T
Converts the entry into a mutable reference to its value.
§Examples
use serde_json::map::Entry;
let mut map = serde_json::Map::new();
map.insert("serde".to_owned(), json!([1, 2, 3]));
match map.entry("serde") {
Entry::Occupied(mut occupied) => {
occupied.into_mut().as_array_mut().unwrap().push(json!(4));
}
Entry::Vacant(_) => unimplemented!(),
}
assert_eq!(map["serde"].as_array().unwrap().len(), 4);
sourcepub fn insert(&mut self, value: T) -> T
pub fn insert(&mut self, value: T) -> T
Sets the value of the entry with the OccupiedEntry
’s key, and returns
the entry’s old value.
§Examples
use serde_json::map::Entry;
let mut map = serde_json::Map::new();
map.insert("serde".to_owned(), json!(12));
match map.entry("serde") {
Entry::Occupied(mut occupied) => {
assert_eq!(occupied.insert(json!(13)), 12);
assert_eq!(occupied.get(), 13);
}
Entry::Vacant(_) => unimplemented!(),
}
sourcepub fn remove(self) -> T
pub fn remove(self) -> T
Takes the value of the entry out of the map, and returns it.
§Examples
use serde_json::map::Entry;
let mut map = serde_json::Map::new();
map.insert("serde".to_owned(), json!(12));
match map.entry("serde") {
Entry::Occupied(occupied) => {
assert_eq!(occupied.remove(), 12);
}
Entry::Vacant(_) => unimplemented!(),
}
Auto Trait Implementations§
impl<'a, T> Freeze for OccupiedEntry<'a, T>
impl<'a, T> RefUnwindSafe for OccupiedEntry<'a, T>where
T: RefUnwindSafe,
impl<'a, T> Send for OccupiedEntry<'a, T>where
T: Send,
impl<'a, T> Sync for OccupiedEntry<'a, T>where
T: Sync,
impl<'a, T> Unpin for OccupiedEntry<'a, T>
impl<'a, T> !UnwindSafe for OccupiedEntry<'a, T>
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