Struct 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<'de, K, V, S> Deserialize<'de> for OnceMap<K, V, S>
where K: Eq + Hash + Deserialize<'de>, V: Deserialize<'de>, S: BuildHasher + Default,

Available on crate feature serde only.
Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. 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
Source§

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

Available on crate feature serde only.
Source§

fn serialize<Ser>(&self, serializer: Ser) -> Result<Ser::Ok, Ser::Error>
where Ser: Serializer,

Serialize this value into the given Serde serializer. 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.
Source§

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

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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,