pub enum Entry<'a, V> {
Occupied(OccupiedEntry<'a, V>),
Vacant(VacantEntry<'a, V>),
}Expand description
A view into a single entry in a table, which may either be vacant or occupied.
This enum is constructed from ExtractMap::entry.
Variants§
Implementations§
Source§impl<'a, V> Entry<'a, V>
impl<'a, V> Entry<'a, V>
Sourcepub fn insert(self, value: V) -> OccupiedEntry<'a, V>
pub fn insert(self, value: V) -> OccupiedEntry<'a, V>
Sets the value of the entry, replacing any existing value if there is one, and returns an OccupiedEntry.
§Example
use extract_map::ExtractMap;
let mut map: ExtractMap<u64, User> = ExtractMap::new();
map.insert(User { id: 1, name: "Cat" });
let entry = map.entry(&1).insert(User { id: 1, name: "Fox" });
assert_eq!(entry.get(), &User { id: 1, name: "Fox" });Sourcepub fn or_insert(self, default: V) -> OccupiedEntry<'a, V>
pub fn or_insert(self, default: V) -> OccupiedEntry<'a, V>
Ensures a value is in the entry by inserting if it was vacant.
Returns an OccupiedEntry pointing to the now-occupied entry.
§Example
use extract_map::ExtractMap;
let mut map: ExtractMap<u64, User> = ExtractMap::new();
// Inserts new entry, as the map is empty.
let entry = map.entry(&1).or_insert(User { id: 1, name: "Fox" });
assert_eq!(entry.get(), &User { id: 1, name: "Fox" });
// Does not insert new entry, as there is already a user with ID 1.
let entry = map.entry(&1).or_insert(User { id: 1, name: "Cat" });
assert_eq!(entry.get(), &User { id: 1, name: "Fox" });Sourcepub fn or_insert_with(self, default: impl FnOnce() -> V) -> OccupiedEntry<'a, V>
pub fn or_insert_with(self, default: impl FnOnce() -> V) -> OccupiedEntry<'a, V>
Ensures a value is in the entry by inserting the result of the function if it was vacant.
Returns an OccupiedEntry pointing to the now-occupied entry.
§Example
use extract_map::ExtractMap;
let mut map: ExtractMap<u64, User> = ExtractMap::new();
// Inserts new entry, as the map is empty.
let entry = map.entry(&1).or_insert_with(|| User { id: 1, name: "Fox" });
assert_eq!(entry.get(), &User { id: 1, name: "Fox" });
// Does not insert new entry, as there is already a user with ID 1.
let entry = map.entry(&1).or_insert_with(|| User { id: 1, name: "Cat" });
assert_eq!(entry.get(), &User { id: 1, name: "Fox" });Sourcepub fn and_modify(self, f: impl FnOnce(&mut V)) -> Self
pub fn and_modify(self, f: impl FnOnce(&mut V)) -> Self
Provides in-place mutable access to an occupied entry, does nothing for a vacant entry.
§Example
use extract_map::ExtractMap;
let mut map: ExtractMap<u64, User> = ExtractMap::new();
map.insert(User { id: 1, name: "Cat"});
map.entry(&1).and_modify(|user| user.name = "Fox");
assert_eq!(map.get(&1), Some(&User { id: 1, name: "Fox"}));Trait Implementations§
Auto Trait Implementations§
impl<'a, V> Freeze for Entry<'a, V>
impl<'a, V> RefUnwindSafe for Entry<'a, V>where
V: RefUnwindSafe,
impl<'a, V> Send for Entry<'a, V>where
V: Send,
impl<'a, V> Sync for Entry<'a, V>where
V: Sync,
impl<'a, V> Unpin for Entry<'a, V>
impl<'a, V> !UnwindSafe for Entry<'a, V>
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