Struct KeyedSet

Source
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,

Source

pub fn new(extractor: Extractor) -> Self

Construct a new map where the key is extracted from the value using extractor.`

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,

Source

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.

Source

pub fn entry<'a, K>(&'a mut self, key: K) -> Entry<'a, T, Extractor, K, S>
where K: Hash, for<'z> <Extractor as KeyExtractor<'z, T>>::Key: Hash + PartialEq<K>,

Obtain an entry in the map, allowing mutable access to the value associated to that key if it exists.

Source

pub fn write(&mut self, value: T) -> &mut T
where 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.

Source

pub fn get<K>(&self, key: &K) -> Option<&T>
where K: Hash, for<'a> <Extractor as KeyExtractor<'a, T>>::Key: Hash + PartialEq<K>,

Access the value associated to the key immutably.

Source

pub fn get_mut<'a, K>( &'a mut self, key: &'a K, ) -> Option<KeyedSetGuard<'a, K, T, Extractor>>
where K: Hash, for<'z> <Extractor as KeyExtractor<'z, T>>::Key: Hash + PartialEq<K>,

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.

Source

pub unsafe fn get_mut_unguarded<'a, K>( &'a mut self, key: &K, ) -> Option<&'a mut T>
where K: Hash, for<'z> <Extractor as KeyExtractor<'z, T>>::Key: Hash + PartialEq<K>,

Access the value associated to the key mutably.

§Safety

Mutating the value in a way that mutates its key may lead to undefined behaviour.

Source

pub fn remove<K>(&mut self, key: &K) -> Option<T>
where K: Hash, for<'z> <Extractor as KeyExtractor<'z, T>>::Key: Hash + PartialEq<K>,

Remove the value associated to the key, returning it if it exists.

Source

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.

Source

pub fn drain(&mut self) -> Drain<'_, T>

Returns an iterator that drains elements from the collection, without affecting the collection’s capacity.

Note that Drain WILL iterate fully on drop, ensuring that all elements are indeed removed, even if you fail to iterate.

Source§

impl<T, Extractor, S> KeyedSet<T, Extractor, S>

Source

pub fn iter(&self) -> Iter<'_, T>

Iterate over the KeyedSet’s values immutably.

Source

pub fn iter_mut(&mut self) -> IterMut<'_, T>

Iterate over the KeyedSet’s values mutably.

Source

pub fn len(&self) -> usize

Returns the number of elements in the KeyedSet

Source

pub fn is_empty(&self) -> bool

Returns true if the KeyedSet is empty.

Trait Implementations§

Source§

impl<T: Clone, Extractor: Clone, S: Clone> Clone for KeyedSet<T, Extractor, S>

Source§

fn clone(&self) -> KeyedSet<T, Extractor, S>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug, Extractor, S> Debug for KeyedSet<T, Extractor, S>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T, Extractor: Default, S: Default> Default for KeyedSet<T, Extractor, S>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T, Extractor, S, Borrower> IEntry<T, Extractor, S, Borrower> for KeyedSet<T, Extractor, S>
where Extractor: for<'a> KeyExtractor<'a, T>, for<'a> <Extractor as KeyExtractor<'a, T>>::Key: Hash, S: BuildHasher,

Source§

fn entry<'a, K>(&'a mut self, key: K) -> Entry<'a, T, Extractor, K, S>
where Borrower: IBorrower<K>, <Borrower as IBorrower<K>>::Borrowed: Hash, for<'z> <Extractor as KeyExtractor<'z, T>>::Key: Hash + PartialEq<<Borrower as IBorrower<K>>::Borrowed>,

Access the entry for key.
Source§

impl<'a, T, Extractor, S> IntoIterator for &'a KeyedSet<T, Extractor, S>

Source§

type Item = &'a T

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a, T, Extractor, S> IntoIterator for &'a mut KeyedSet<T, Extractor, S>

Source§

type Item = &'a mut T

The type of the elements being iterated over.
Source§

type IntoIter = IterMut<'a, T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<T, Extractor, S> Freeze for KeyedSet<T, Extractor, S>
where S: Freeze, Extractor: Freeze,

§

impl<T, Extractor, S> RefUnwindSafe for KeyedSet<T, Extractor, S>
where S: RefUnwindSafe, Extractor: RefUnwindSafe, T: RefUnwindSafe,

§

impl<T, Extractor, S> Send for KeyedSet<T, Extractor, S>
where S: Send, Extractor: Send, T: Send,

§

impl<T, Extractor, S> Sync for KeyedSet<T, Extractor, S>
where S: Sync, Extractor: Sync, T: Sync,

§

impl<T, Extractor, S> Unpin for KeyedSet<T, Extractor, S>
where S: Unpin, Extractor: Unpin, T: Unpin,

§

impl<T, Extractor, S> UnwindSafe for KeyedSet<T, Extractor, S>
where S: UnwindSafe, Extractor: UnwindSafe, T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.