[][src]Struct weak_table::WeakHashSet

pub struct WeakHashSet<T, S = RandomState>(_);

A hash set with weak elements, hashed on element value.

When a weak pointer expires, its mapping is lazily removed.

Implementations

impl<T: WeakKey> WeakHashSet<T, RandomState>[src]

pub fn new() -> Self[src]

Creates an empty WeakHashSet.

pub fn with_capacity(capacity: usize) -> Self[src]

Creates an empty WeakHashSet with the given capacity.

impl<T: WeakKey, S: BuildHasher> WeakHashSet<T, S>[src]

pub fn with_hasher(hash_builder: S) -> Self[src]

Creates an empty WeakHashSet with the given capacity and hasher.

pub fn with_capacity_and_hasher(capacity: usize, hash_builder: S) -> Self[src]

Creates an empty WeakHashSet with the given capacity and hasher.

pub fn hasher(&self) -> &S[src]

Returns a reference to the map's BuildHasher.

pub fn capacity(&self) -> usize[src]

Returns the number of elements the map can hold without reallocating.

pub fn remove_expired(&mut self)[src]

Removes all mappings whose keys have expired.

pub fn reserve(&mut self, additional_capacity: usize)[src]

Reserves room for additional elements.

pub fn shrink_to_fit(&mut self)[src]

Shrinks the capacity to the minimum allowed to hold the current number of elements.

pub fn len(&self) -> usize[src]

Returns an over-approximation of the number of elements.

pub fn is_empty(&self) -> bool[src]

Is the set empty?

Note that this may return false even if all keys in the set have expired, if they haven't been collected yet.

pub fn load_factor(&self) -> f32[src]

The proportion of buckets that are used.

This is an over-approximation because of expired elements.

pub fn clear(&mut self)[src]

Removes all associations from the map.

pub fn contains<Q: ?Sized>(&self, key: &Q) -> bool where
    Q: Eq + Hash,
    T::Key: Borrow<Q>, 
[src]

Returns true if the map contains the specified key.

pub fn get<Q: ?Sized>(&self, key: &Q) -> Option<T::Strong> where
    Q: Eq + Hash,
    T::Key: Borrow<Q>, 
[src]

Gets a strong reference to the given key, if found.

Examples

use weak_table::WeakHashSet;
use std::rc::{Rc, Weak};
use std::ops::Deref;

let mut set: WeakHashSet<Weak<String>> = WeakHashSet::new();

let a = Rc::new("a".to_owned());
set.insert(a.clone());

let also_a = set.get("a").unwrap();

assert!(Rc::ptr_eq( &a, &also_a ));

pub fn insert(&mut self, key: T::Strong) -> bool[src]

Unconditionally inserts the value, returning the old value if already present. Does not replace the key.

pub fn remove<Q: ?Sized>(&mut self, key: &Q) -> bool where
    Q: Eq + Hash,
    T::Key: Borrow<Q>, 
[src]

Removes the entry with the given key, if it exists, and returns the value.

pub fn retain<F>(&mut self, f: F) where
    F: FnMut(T::Strong) -> bool
[src]

Removes all mappings not satisfying the given predicate.

Also removes any expired mappings.

pub fn is_subset<S1>(&self, other: &WeakHashSet<T, S1>) -> bool where
    S1: BuildHasher
[src]

Is self a subset of other?

impl<T: WeakKey, S> WeakHashSet<T, S>[src]

pub fn iter(&self) -> Iter<T>[src]

Gets an iterator over the keys and values.

pub fn drain(&mut self) -> Drain<T>[src]

Gets a draining iterator, which removes all the values but retains the storage.

Trait Implementations

impl<T: Clone, S: Clone> Clone for WeakHashSet<T, S>[src]

impl<T: WeakKey, S> Debug for WeakHashSet<T, S> where
    T::Strong: Debug
[src]

impl<T: WeakKey, S: BuildHasher + Default> Default for WeakHashSet<T, S>[src]

impl<T: WeakKey, S: BuildHasher> Eq for WeakHashSet<T, S> where
    T::Key: Eq
[src]

impl<T: WeakKey, S: BuildHasher> Extend<<T as WeakElement>::Strong> for WeakHashSet<T, S>[src]

impl<T, S> FromIterator<<T as WeakElement>::Strong> for WeakHashSet<T, S> where
    T: WeakKey,
    S: BuildHasher + Default
[src]

impl<T: WeakKey, S> IntoIterator for WeakHashSet<T, S>[src]

type Item = T::Strong

The type of the elements being iterated over.

type IntoIter = IntoIter<T>

Which kind of iterator are we turning this into?

impl<'a, T: WeakKey, S> IntoIterator for &'a WeakHashSet<T, S>[src]

type Item = T::Strong

The type of the elements being iterated over.

type IntoIter = Iter<'a, T>

Which kind of iterator are we turning this into?

impl<T, S, S1> PartialEq<WeakHashSet<T, S1>> for WeakHashSet<T, S> where
    T: WeakKey,
    S: BuildHasher,
    S1: BuildHasher
[src]

Auto Trait Implementations

impl<T, S> RefUnwindSafe for WeakHashSet<T, S> where
    S: RefUnwindSafe,
    T: RefUnwindSafe

impl<T, S> Send for WeakHashSet<T, S> where
    S: Send,
    T: Send

impl<T, S> Sync for WeakHashSet<T, S> where
    S: Sync,
    T: Sync

impl<T, S> Unpin for WeakHashSet<T, S> where
    S: Unpin

impl<T, S> UnwindSafe for WeakHashSet<T, S> where
    S: UnwindSafe,
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.