Struct cachemap::CacheMap [−][src]
An insert-only map for caching the result of functions
Implementations
impl<K: Hash + Eq, V> CacheMap<K, V>
[src]
pub fn cache<F: FnOnce() -> V>(&self, key: K, f: F) -> ArcRef<'_, V>
[src]
Fetch the value associated with the key, or run the profvided function to insert one.
#Example
use cachemap::CacheMap; let m = CacheMap::new(); let fst = m.cache("key", || 5u32).as_ref(); let snd = m.cache("key", || 7u32).as_ref(); assert_eq!(*fst, *snd); assert_eq!(*fst, 5u32);
impl<K: Hash + Eq, V: ?Sized> CacheMap<K, V>
[src]
pub fn new() -> Self
[src]
Creates a new CacheMap
pub fn cache_arc<F: FnOnce() -> Arc<V>>(&self, key: K, f: F) -> ArcRef<'_, V>
[src]
Fetch the value associated with the key, or run the profvided function to insert one.
With this version, the function returns an Arc
#Example
use cachemap::CacheMap; let m: CacheMap<_, [usize]> = CacheMap::new(); let a = m.cache_arc("a", || { let a = &[1,2,3][..]; a.into() }).as_ref(); let b = m.cache_arc("b", || { let b = &[9,9][..]; b.into() }).as_ref(); assert_eq!(a, &[1,2,3]); assert_eq!(b, &[9,9]);
Auto Trait Implementations
impl<K, V> !RefUnwindSafe for CacheMap<K, V>
impl<K, V: ?Sized> Send for CacheMap<K, V> where
K: Send,
V: Send + Sync,
K: Send,
V: Send + Sync,
impl<K, V: ?Sized> Sync for CacheMap<K, V> where
K: Send + Sync,
V: Send + Sync,
K: Send + Sync,
V: Send + Sync,
impl<K, V: ?Sized> Unpin for CacheMap<K, V>
impl<K, V: ?Sized> UnwindSafe for CacheMap<K, V> where
K: UnwindSafe,
V: RefUnwindSafe,
K: UnwindSafe,
V: RefUnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,