pub struct KeyedSet<T, Extractor, S = DefaultHashBuilder> { /* private fields */ }
Expand description
A HashMap<K, V>
where K
is a part of V
Implementations§
Source§impl<T, Extractor> KeyedSet<T, Extractor>where
Extractor: for<'a> KeyExtractor<'a, T>,
for<'a> <Extractor as KeyExtractor<'a, T>>::Key: Hash,
impl<T, Extractor> KeyedSet<T, Extractor>where
Extractor: for<'a> KeyExtractor<'a, T>,
for<'a> <Extractor as KeyExtractor<'a, T>>::Key: Hash,
Source§impl<T, Extractor, S> KeyedSet<T, Extractor, S>where
Extractor: for<'a> KeyExtractor<'a, T>,
for<'a> <Extractor as KeyExtractor<'a, T>>::Key: Hash,
S: BuildHasher,
impl<T, Extractor, S> KeyedSet<T, Extractor, S>where
Extractor: for<'a> KeyExtractor<'a, T>,
for<'a> <Extractor as KeyExtractor<'a, T>>::Key: Hash,
S: BuildHasher,
Sourcepub fn insert(&mut self, value: T) -> Option<T>where
for<'a, 'b> <Extractor as KeyExtractor<'a, T>>::Key: PartialEq<<Extractor as KeyExtractor<'b, T>>::Key>,
pub fn insert(&mut self, value: T) -> Option<T>where
for<'a, 'b> <Extractor as KeyExtractor<'a, T>>::Key: PartialEq<<Extractor as KeyExtractor<'b, T>>::Key>,
Inserts a value into the map.
Sourcepub fn entry<'a, K>(&'a mut self, key: K) -> Entry<'a, T, Extractor, K, S>
pub fn entry<'a, K>(&'a mut self, key: K) -> Entry<'a, T, Extractor, K, S>
Obtain an entry in the map, allowing mutable access to the value associated to that key if it exists.
Sourcepub fn write(&mut self, value: T) -> &mut Twhere
for<'a, 'b> <Extractor as KeyExtractor<'a, T>>::Key: PartialEq<<Extractor as KeyExtractor<'b, T>>::Key>,
pub fn write(&mut self, value: T) -> &mut Twhere
for<'a, 'b> <Extractor as KeyExtractor<'a, T>>::Key: PartialEq<<Extractor as KeyExtractor<'b, T>>::Key>,
Similar to KeyedSet::insert
, but returns a mutable reference to the inserted value instead of the previous value.
Sourcepub fn get_mut<'a, K>(
&'a mut self,
key: &'a K,
) -> Option<KeyedSetGuard<'a, K, T, Extractor>>
pub fn get_mut<'a, K>( &'a mut self, key: &'a K, ) -> Option<KeyedSetGuard<'a, K, T, Extractor>>
Access the value associated to the key mutably.
The returned KeyedSetGuard
will panic on drop if the value is modified in a way that modifies its key.
Sourcepub unsafe fn get_mut_unguarded<'a, K>(
&'a mut self,
key: &K,
) -> Option<&'a mut T>
pub unsafe fn get_mut_unguarded<'a, K>( &'a mut self, key: &K, ) -> Option<&'a mut T>
Access the value associated to the key mutably.
§Safety
Mutating the value in a way that mutates its key may lead to undefined behaviour.
Sourcepub fn remove<K>(&mut self, key: &K) -> Option<T>
pub fn remove<K>(&mut self, key: &K) -> Option<T>
Remove the value associated to the key, returning it if it exists.
Sourcepub fn drain_where<F: FnMut(&mut T) -> bool>(
&mut self,
predicate: F,
) -> DrainFilter<'_, T, F> ⓘ
pub fn drain_where<F: FnMut(&mut T) -> bool>( &mut self, predicate: F, ) -> DrainFilter<'_, T, F> ⓘ
Returns an iterator that drains elements that match the provided predicate, while removing them from the set.
Note that DrainFilter
WILL iterate fully on drop, ensuring that all elements matching your predicate are always removed, even if you fail to iterate.