Struct LazyMap

Source
pub struct LazyMap<K, V, S = RandomState, F = fn(&K) -> V> { /* private fields */ }
Expand description

A map where values are automatically filled at access.

This type has less overhead than crate::sync::LazyMap but it cannot be shared across threads.

let map = once_map::unsync::LazyMap::new(|x: &i32| x.to_string());

assert_eq!(&map[&3], "3");
assert_eq!(map.get(&-67), "-67");

Implementations§

Source§

impl<K, V, F> LazyMap<K, V, RandomState, F>

Source

pub fn new(f: F) -> Self

Source§

impl<K, V, S, F> LazyMap<K, V, S, F>

Source

pub const fn with_hasher(hash_builder: S, f: F) -> Self

Source

pub fn clear(&mut self)

Removes all entries from the map.

Source§

impl<K, V, S, F> LazyMap<K, V, S, F>
where K: Eq + Hash, S: BuildHasher, F: Fn(&K) -> V, V: StableDeref,

Source

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

Source§

impl<K, V, S, F> LazyMap<K, V, S, F>
where K: Eq + Hash, S: BuildHasher, F: Fn(&K) -> V, V: Clone,

Source

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

Source§

impl<K, V, S, F> LazyMap<K, V, S, F>
where K: Eq + Hash, S: BuildHasher, F: Fn(&K) -> V,

Source

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

Source§

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

Source

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

Trait Implementations§

Source§

impl<K, V, S> Debug for LazyMap<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: Default, S: Default> Default for LazyMap<K, V, S>

Creates a LazyMap that fills all values with V::default().

Source§

fn default() -> Self

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

impl<K, V, S, F, Q> Index<&Q> for LazyMap<K, V, S, F>
where K: Eq + Hash, S: BuildHasher, F: Fn(&K) -> V, V: StableDeref, Q: Hash + ToOwnedEquivalent<K> + ?Sized,

Source§

type Output = <V as Deref>::Target

The returned type after indexing.
Source§

fn index(&self, key: &Q) -> &V::Target

Performs the indexing (container[index]) operation. Read more

Auto Trait Implementations§

§

impl<K, V, S = RandomState, F = fn(&K) -> V> !Freeze for LazyMap<K, V, S, F>

§

impl<K, V, S = RandomState, F = fn(&K) -> V> !RefUnwindSafe for LazyMap<K, V, S, F>

§

impl<K, V, S, F> Send for LazyMap<K, V, S, F>
where F: Send, S: Send, K: Send, V: Send,

§

impl<K, V, S = RandomState, F = fn(&K) -> V> !Sync for LazyMap<K, V, S, F>

§

impl<K, V, S, F> Unpin for LazyMap<K, V, S, F>
where F: Unpin, S: Unpin, K: Unpin, V: Unpin,

§

impl<K, V, S, F> UnwindSafe for LazyMap<K, V, S, F>

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