1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-29 04:40:03 -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 { impl CacheStorage {
pub fn cache<Cache: CacheTrait + Default>(&mut self) -> &mut Cache { pub fn cache<Cache: CacheTrait + Default>(&mut self) -> &mut Cache {
#[expect(clippy::unwrap_used)] let cache = self
self.caches .caches
.entry(std::any::TypeId::of::<Cache>()) .entry(std::any::TypeId::of::<Cache>())
.or_insert_with(|| Box::<Cache>::default()) .or_insert_with(|| Box::<Cache>::default());
.as_any_mut()
#[expect(clippy::unwrap_used)]
(cache.as_mut() as &mut dyn std::any::Any)
.downcast_mut::<Cache>() .downcast_mut::<Cache>()
.unwrap() .unwrap()
} }

View File

@@ -1,11 +1,9 @@
/// A cache, storing some value for some length of time. /// A cache, storing some value for some length of time.
#[expect(clippy::len_without_is_empty)] #[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. /// Call once per frame to evict cache.
fn update(&mut self); fn update(&mut self);
/// Number of values currently in the cache. /// Number of values currently in the cache.
fn len(&self) -> usize; 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 { fn len(&self) -> usize {
self.cache.len() 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 { fn len(&self) -> usize {
self.cache.len() 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 { 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>() .downcast_ref::<P>()
.expect("PluginHandle: plugin is not of the expected type") .expect("PluginHandle: plugin is not of the expected type")
} }
pub fn typed_plugin_mut<P: Plugin + 'static>(&mut self) -> &mut P { 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>() .downcast_mut::<P>()
.expect("PluginHandle: plugin is not of the expected type") .expect("PluginHandle: plugin is not of the expected type")
} }