Struct egui::cache::cache_storage::CacheStorage
source · pub struct CacheStorage {
caches: HashMap<TypeId, Box<dyn CacheTrait>>,
}
Expand description
A typemap of many caches, all implemented with CacheTrait
.
You can access egui’s caches via crate::Memory::caches
,
found with crate::Context::memory_mut
.
use egui::cache::{CacheStorage, ComputerMut, FrameCache};
#[derive(Default)]
struct CharCounter {}
impl ComputerMut<&str, usize> for CharCounter {
fn compute(&mut self, s: &str) -> usize {
s.chars().count()
}
}
type CharCountCache<'a> = FrameCache<usize, CharCounter>;
let mut cache = cache_storage.cache::<CharCountCache<'_>>();
assert_eq!(cache.get("hello"), 5);
Fields§
§caches: HashMap<TypeId, Box<dyn CacheTrait>>
Implementations§
source§impl CacheStorage
impl CacheStorage
pub fn cache<Cache: CacheTrait + Default>(&mut self) -> &mut Cache
sourcefn num_values(&self) -> usize
fn num_values(&self) -> usize
Total number of cached values
Trait Implementations§
source§impl Clone for CacheStorage
impl Clone for CacheStorage
source§impl Debug for CacheStorage
impl Debug for CacheStorage
source§impl Default for CacheStorage
impl Default for CacheStorage
source§fn default() -> CacheStorage
fn default() -> CacheStorage
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for CacheStorage
impl !RefUnwindSafe for CacheStorage
impl Send for CacheStorage
impl Sync for CacheStorage
impl Unpin for CacheStorage
impl !UnwindSafe for CacheStorage
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)