[−][src]Struct high_mem_utils::LazyCache
A lazy-iniatialiazed cache for a Fn closure with a constant constructor.
Fields
closure: C
Methods
impl<P: Ord + Clone, V: Clone, C: Fn(P) -> V> LazyCache<P, V, C>
[src]
pub const fn new(closure: C) -> Self
[src]
Construct a cache for a closure that is initialized in the first call to call_cache.
This is particularly useful for fn pointers of recurrently used functions because it can be used on statics,althought you need make them mutable for actually call call_cache.
pub fn call_cache(&mut self, arg: P) -> V
[src]
calls the inner closure with the givem arg after init the cache if it did not before.
Panics
If the given closure panic the variable reading them from the MaybeUninit is guranteed to not drop and the Drop impl will do the job.
Examples
use high_mem_utils::LazyCache; fn foo(num: u32) -> u32 { num } let mut cache = LazyCache::new(foo); assert_eq!(cache.call_cache(2), 2); assert_eq!(cache.call_cache(2), 2); assert_eq!(cache.call_cache(4), 4);
pub fn pop(&mut self, arg: &P) -> Option<V>
[src]
This method removes an argument from the cache and returns the value or None if there's no one or the cache is uninitialized.
Examples
use high_mem_utils::LazyCache; fn foo(num: u32) -> u32 { num } let mut cache = LazyCache::new(foo); assert_eq!(cache.call_cache(2), 2); assert_eq!(cache.pop(&2), Some(2)); assert_eq!(cache.pop(&2), None);
pub fn clear(&mut self)
[src]
Clears the cache,removing all their values.This is no-op if the cache is not initialized.
pub fn is_init(&self) -> bool
[src]
Returns true if the cache is initialized,not neccesarily filled with an argument. Use
for that purporse.
pub fn is_empty(&self) -> bool
[src]
Returns true if the cache has no arguments or if it's not initialized.
Trait Implementations
Auto Trait Implementations
impl<P, V, C> RefUnwindSafe for LazyCache<P, V, C> where
C: RefUnwindSafe,
P: RefUnwindSafe,
V: RefUnwindSafe,
C: RefUnwindSafe,
P: RefUnwindSafe,
V: RefUnwindSafe,
impl<P, V, C> Send for LazyCache<P, V, C> where
C: Send,
P: Send,
V: Send,
C: Send,
P: Send,
V: Send,
impl<P, V, C> Sync for LazyCache<P, V, C> where
C: Sync,
P: Sync,
V: Sync,
C: Sync,
P: Sync,
V: Sync,
impl<P, V, C> Unpin for LazyCache<P, V, C> where
C: Unpin,
P: Unpin,
V: Unpin,
C: Unpin,
P: Unpin,
V: Unpin,
impl<P, V, C> UnwindSafe for LazyCache<P, V, C> where
C: UnwindSafe,
P: RefUnwindSafe + UnwindSafe,
V: RefUnwindSafe + UnwindSafe,
C: UnwindSafe,
P: RefUnwindSafe + UnwindSafe,
V: RefUnwindSafe + UnwindSafe,
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,
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.
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>,