Struct once_map::sync::OnceMap

source ·
pub struct OnceMap<K, V, S = RandomState> { /* private fields */ }

Implementations§

source§

impl<K, V> OnceMap<K, V>

source

pub fn new() -> Self

Creates an empty OnceMap.

source§

impl<K, V, S> OnceMap<K, V, S>

source

pub fn with_hasher(hash_builder: S) -> Self

Creates an empty OnceMap which will use the given hash builder to hash keys.

source§

impl<K, V, S> OnceMap<K, V, S>

source

pub fn clear(&mut self)

Removes all key-value pairs from the map, but keeps the allocated memory.

source

pub fn values_mut(&mut self) -> impl Iterator<Item = &mut V>

source

pub fn iter_mut(&mut self) -> impl Iterator<Item = (&K, &mut V)>

source

pub fn into_iter(self) -> impl Iterator<Item = (K, V)>

source

pub fn hasher(&self) -> &S

Returns a reference to the map’s BuildHasher.

source

pub fn read_only_view(&self) -> ReadOnlyView<'_, K, V, S>

Locks the whole map for reading.

This enables more methods, such as iterating on the maps, but will cause a deadlock if trying to insert values in the map from the same thread.

source§

impl<K, V, S> OnceMap<K, V, S>
where K: Send, V: Send,

source

pub fn into_par_iter(self) -> impl ParallelIterator<Item = (K, V)>

Available on crate feature rayon only.
source§

impl<K, V, S> OnceMap<K, V, S>
where K: Eq + Hash, S: BuildHasher,

source

pub fn contains_key<Q>(&self, key: &Q) -> bool
where Q: Hash + Equivalent<K> + ?Sized,

Returns true if the map contains a value for the specified key.

source

pub fn remove<Q>(&mut self, key: &Q) -> Option<V>
where Q: Hash + Equivalent<K> + ?Sized,

source

pub fn remove_entry<Q>(&mut self, key: &Q) -> Option<(K, V)>
where Q: Hash + Equivalent<K> + ?Sized,

source§

impl<K, V, S> OnceMap<K, V, S>
where K: Eq + Hash, S: BuildHasher, V: StableDeref,

source

pub fn get<Q>(&self, key: &Q) -> Option<&V::Target>
where Q: Hash + Equivalent<K> + ?Sized,

Returns a reference to the value corresponding to the key.

source

pub fn insert(&self, key: K, make_val: impl FnOnce(&K) -> V) -> &V::Target

Returns a reference to the value corresponding to the key or insert one with the given closure.

source

pub fn try_insert<E>( &self, key: K, make_val: impl FnOnce(&K) -> Result<V, E> ) -> Result<&V::Target, E>

Same as insert but the closure is allowed to fail.

If the closure is called and an error is returned, no value is stored in the map.

source§

impl<K, V, S> OnceMap<K, V, S>
where K: Eq + Hash, S: BuildHasher, V: Clone,

source

pub fn get_cloned<Q>(&self, key: &Q) -> Option<V>
where Q: Hash + Equivalent<K> + ?Sized,

source

pub fn insert_cloned(&self, key: K, make_val: impl FnOnce(&K) -> V) -> V

source

pub fn try_insert_cloned<E>( &self, key: K, make_val: impl FnOnce(&K) -> Result<V, E> ) -> Result<V, E>

source§

impl<K, V, S> OnceMap<K, V, S>
where K: Eq + Hash, S: BuildHasher,

source

pub fn map_get<Q, T>( &self, key: &Q, with_result: impl FnOnce(&K, &V) -> T ) -> Option<T>
where Q: Hash + Equivalent<K> + ?Sized,

source

pub fn map_insert<T>( &self, key: K, make_val: impl FnOnce(&K) -> V, with_result: impl FnOnce(&K, &V) -> T ) -> T

source

pub fn map_insert_ref<Q, T>( &self, key: &Q, make_key: impl FnOnce(&Q) -> K, make_val: impl FnOnce(&K) -> V, with_result: impl FnOnce(&K, &V) -> T ) -> T
where Q: Hash + Equivalent<K> + ?Sized,

source

pub fn map_try_insert<T, E>( &self, key: K, make_val: impl FnOnce(&K) -> Result<V, E>, with_result: impl FnOnce(&K, &V) -> T ) -> Result<T, E>

source

pub fn map_try_insert_ref<Q, T, E>( &self, key: &Q, make_key: impl FnOnce(&Q) -> K, make_val: impl FnOnce(&K) -> Result<V, E>, with_result: impl FnOnce(&K, &V) -> T ) -> Result<T, E>
where Q: Hash + Equivalent<K> + ?Sized,

source

pub fn get_or_try_insert<T, U, E>( &self, key: K, data: T, on_vacant: impl FnOnce(T, &K) -> Result<(V, U), E>, on_occupied: impl FnOnce(T, &K, &V) -> U ) -> Result<U, E>

source

pub fn get_or_try_insert_ref<Q, T, U, E>( &self, key: &Q, data: T, make_key: impl FnOnce(&Q) -> K, on_vacant: impl FnOnce(T, &K) -> Result<(V, U), E>, on_occupied: impl FnOnce(T, &K, &V) -> U ) -> Result<U, E>
where Q: Hash + Equivalent<K> + ?Sized,

Trait Implementations§

source§

impl<K, V, S> Debug for OnceMap<K, V, S>
where K: Debug, V: Debug,

source§

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

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

impl<K, V, S: Default> Default for OnceMap<K, V, S>

source§

fn default() -> Self

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

impl<K, V, S> Extend<(K, V)> for &OnceMap<K, V, S>
where K: Eq + Hash, S: BuildHasher,

source§

fn extend<T: IntoIterator<Item = (K, V)>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl<K, V, S> Extend<(K, V)> for OnceMap<K, V, S>
where K: Eq + Hash, S: BuildHasher,

source§

fn extend<T: IntoIterator<Item = (K, V)>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl<K, V, S, const N: usize> From<[(K, V); N]> for OnceMap<K, V, S>
where K: Eq + Hash, S: BuildHasher + Default,

source§

fn from(array: [(K, V); N]) -> Self

Converts to this type from the input type.
source§

impl<K, V, S> FromIterator<(K, V)> for OnceMap<K, V, S>
where K: Eq + Hash, S: BuildHasher + Default,

source§

fn from_iter<T: IntoIterator<Item = (K, V)>>(iter: T) -> Self

Creates a value from an iterator. Read more
source§

impl<K, V, S> FromParallelIterator<(K, V)> for OnceMap<K, V, S>
where K: Eq + Hash + Send + Sync, V: Send + Sync, S: BuildHasher + Default + Sync,

Available on crate feature rayon only.
source§

fn from_par_iter<I>(par_iter: I) -> Self
where I: IntoParallelIterator<Item = (K, V)>,

Creates an instance of the collection from the parallel iterator par_iter. Read more
source§

impl<K, V, S> ParallelExtend<(K, V)> for &OnceMap<K, V, S>
where K: Eq + Hash + Send + Sync, V: Send + Sync, S: BuildHasher + Sync,

Available on crate feature rayon only.
source§

fn par_extend<I>(&mut self, par_iter: I)
where I: IntoParallelIterator<Item = (K, V)>,

Extends an instance of the collection with the elements drawn from the parallel iterator par_iter. Read more
source§

impl<K, V, S> ParallelExtend<(K, V)> for OnceMap<K, V, S>
where K: Eq + Hash + Send + Sync, V: Send + Sync, S: BuildHasher + Sync,

Available on crate feature rayon only.
source§

fn par_extend<I>(&mut self, par_iter: I)
where I: IntoParallelIterator<Item = (K, V)>,

Extends an instance of the collection with the elements drawn from the parallel iterator par_iter. Read more

Auto Trait Implementations§

§

impl<K, V, S> Freeze for OnceMap<K, V, S>
where S: Freeze,

§

impl<K, V, S = RandomState> !RefUnwindSafe for OnceMap<K, V, S>

§

impl<K, V, S> Send for OnceMap<K, V, S>
where S: Send, K: Send, V: Send,

§

impl<K, V, S> Sync for OnceMap<K, V, S>
where S: Sync, K: Send + Sync, V: Send + Sync,

§

impl<K, V, S> Unpin for OnceMap<K, V, S>
where S: Unpin,

§

impl<K, V, S = RandomState> !UnwindSafe for OnceMap<K, V, S>

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> 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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

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

§

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

§

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.