pub enum Entry<'a, T, V, Ix> {
Occupied(OccupiedEntry<'a, T, V, Ix>),
Vacant(VacantEntry<'a, T, V, Ix>),
}Expand description
A view into a single entry in a map, which may either be vacant or occupied.
Variants§
Occupied(OccupiedEntry<'a, T, V, Ix>)
An occupied entry.
Vacant(VacantEntry<'a, T, V, Ix>)
A vacant entry.
Implementations§
Source§impl<'a, T, V, Ix> Entry<'a, T, V, Ix>where
T: Ord,
Ix: IndexType,
impl<'a, T, V, Ix> Entry<'a, T, V, Ix>where
T: Ord,
Ix: IndexType,
Sourcepub fn or_insert(self, default: V) -> &'a mut V
pub fn or_insert(self, default: V) -> &'a mut V
Ensures a value is in the entry by inserting the default if empty, and returns a mutable reference to the value in the entry.
§Example
use rb_interval_map::{Interval, IntervalMap, Entry};
let mut map = IntervalMap::new();
assert!(matches!(map.entry(Interval::new(1, 2)), Entry::Vacant(_)));
map.entry(Interval::new(1, 2)).or_insert(3);
assert!(matches!(map.entry(Interval::new(1, 2)), Entry::Occupied(_)));
assert_eq!(map.get(&Interval::new(1, 2)), Some(&3));Sourcepub fn and_modify<F>(self, f: F) -> Self
pub fn and_modify<F>(self, f: F) -> Self
Provides in-place mutable access to an occupied entry before any potential inserts into the map.
§Panics
This method panics when the node is a sentinel node
§Example
use rb_interval_map::{Interval, IntervalMap, Entry};
let mut map = IntervalMap::new();
map.insert(Interval::new(6, 7), 3);
assert!(matches!(map.entry(Interval::new(6, 7)), Entry::Occupied(_)));
map.entry(Interval::new(6, 7)).and_modify(|v| *v += 1);
assert_eq!(map.get(&Interval::new(6, 7)), Some(&4));Trait Implementations§
Auto Trait Implementations§
impl<'a, T, V, Ix> Freeze for Entry<'a, T, V, Ix>
impl<'a, T, V, Ix> RefUnwindSafe for Entry<'a, T, V, Ix>
impl<'a, T, V, Ix> Send for Entry<'a, T, V, Ix>
impl<'a, T, V, Ix> Sync for Entry<'a, T, V, Ix>
impl<'a, T, V, Ix> Unpin for Entry<'a, T, V, Ix>
impl<'a, T, V, Ix> !UnwindSafe for Entry<'a, T, V, Ix>
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