1
0
mirror of https://github.com/emilk/egui.git synced 2026-06-26 22:53:14 -04:00

Remove CacheTrait::as_any_mut (#7833)

* Part of https://github.com/emilk/egui/issues/5876

No longer needed on modern MSRV
This commit is contained in:
Emil Ernerfeldt
2026-01-05 18:33:38 +01:00
committed by GitHub
parent f26d7d8072
commit f8e763378a
5 changed files with 9 additions and 17 deletions

View File

@@ -28,11 +28,13 @@ pub struct CacheStorage {
impl CacheStorage {
pub fn cache<Cache: CacheTrait + Default>(&mut self) -> &mut Cache {
#[expect(clippy::unwrap_used)]
self.caches
let cache = self
.caches
.entry(std::any::TypeId::of::<Cache>())
.or_insert_with(|| Box::<Cache>::default())
.as_any_mut()
.or_insert_with(|| Box::<Cache>::default());
#[expect(clippy::unwrap_used)]
(cache.as_mut() as &mut dyn std::any::Any)
.downcast_mut::<Cache>()
.unwrap()
}

View File

@@ -1,11 +1,9 @@
/// A cache, storing some value for some length of time.
#[expect(clippy::len_without_is_empty)]
pub trait CacheTrait: 'static + Send + Sync {
pub trait CacheTrait: 'static + Send + Sync + std::any::Any {
/// Call once per frame to evict cache.
fn update(&mut self);
/// Number of values currently in the cache.
fn len(&self) -> usize;
fn as_any_mut(&mut self) -> &mut dyn std::any::Any;
}

View File

@@ -79,8 +79,4 @@ impl<Value: 'static + Send + Sync, Computer: 'static + Send + Sync> CacheTrait
fn len(&self) -> usize {
self.cache.len()
}
fn as_any_mut(&mut self) -> &mut dyn std::any::Any {
self
}
}

View File

@@ -54,8 +54,4 @@ where
fn len(&self) -> usize {
self.cache.len()
}
fn as_any_mut(&mut self) -> &mut dyn std::any::Any {
self
}
}

View File

@@ -120,13 +120,13 @@ impl PluginHandle {
}
fn typed_plugin<P: Plugin + 'static>(&self) -> &P {
(&*self.plugin as &dyn std::any::Any)
(self.plugin.as_ref() as &dyn std::any::Any)
.downcast_ref::<P>()
.expect("PluginHandle: plugin is not of the expected type")
}
pub fn typed_plugin_mut<P: Plugin + 'static>(&mut self) -> &mut P {
(&mut *self.plugin as &mut dyn std::any::Any)
(self.plugin.as_mut() as &mut dyn std::any::Any)
.downcast_mut::<P>()
.expect("PluginHandle: plugin is not of the expected type")
}