pub struct SimpleCache<T: Clone> { /* private fields */ }
Expand description
A simple cache implementation that stores a single optional value.
This cache can hold at most one value at a time. When a value is set, it replaces any previously stored value. When retrieved, it returns a clone of the stored value.
§Type Parameters
T
- The type of value to cache. Must implement Clone.
§Example
use zed::SimpleCache;
use zed::capsule::Cache;
let mut cache = SimpleCache::<i32>::new();
// Initially empty
assert_eq!(cache.get(), None);
// Set a value
cache.set(42);
assert_eq!(cache.get(), Some(42));
// Set another value (replaces the first)
cache.set(100);
assert_eq!(cache.get(), Some(100));
Implementations§
Trait Implementations§
Source§impl<T: Clone> Cache<T> for SimpleCache<T>
impl<T: Clone> Cache<T> for SimpleCache<T>
Source§impl<T: Clone + Clone> Clone for SimpleCache<T>
impl<T: Clone + Clone> Clone for SimpleCache<T>
Source§fn clone(&self) -> SimpleCache<T>
fn clone(&self) -> SimpleCache<T>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations§
impl<T> Freeze for SimpleCache<T>where
T: Freeze,
impl<T> RefUnwindSafe for SimpleCache<T>where
T: RefUnwindSafe,
impl<T> Send for SimpleCache<T>where
T: Send,
impl<T> Sync for SimpleCache<T>where
T: Sync,
impl<T> Unpin for SimpleCache<T>where
T: Unpin,
impl<T> UnwindSafe for SimpleCache<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more