From f8e763378a52b90ae418fc17af3482a131629328 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Mon, 5 Jan 2026 18:33:38 +0100 Subject: [PATCH] Remove `CacheTrait::as_any_mut` (#7833) * Part of https://github.com/emilk/egui/issues/5876 No longer needed on modern MSRV --- crates/egui/src/cache/cache_storage.rs | 10 ++++++---- crates/egui/src/cache/cache_trait.rs | 4 +--- crates/egui/src/cache/frame_cache.rs | 4 ---- crates/egui/src/cache/frame_publisher.rs | 4 ---- crates/egui/src/plugin.rs | 4 ++-- 5 files changed, 9 insertions(+), 17 deletions(-) diff --git a/crates/egui/src/cache/cache_storage.rs b/crates/egui/src/cache/cache_storage.rs index 255eca2d5..26e7d04ba 100644 --- a/crates/egui/src/cache/cache_storage.rs +++ b/crates/egui/src/cache/cache_storage.rs @@ -28,11 +28,13 @@ pub struct CacheStorage { impl CacheStorage { pub fn cache(&mut self) -> &mut Cache { - #[expect(clippy::unwrap_used)] - self.caches + let cache = self + .caches .entry(std::any::TypeId::of::()) - .or_insert_with(|| Box::::default()) - .as_any_mut() + .or_insert_with(|| Box::::default()); + + #[expect(clippy::unwrap_used)] + (cache.as_mut() as &mut dyn std::any::Any) .downcast_mut::() .unwrap() } diff --git a/crates/egui/src/cache/cache_trait.rs b/crates/egui/src/cache/cache_trait.rs index fc00a9880..54144c724 100644 --- a/crates/egui/src/cache/cache_trait.rs +++ b/crates/egui/src/cache/cache_trait.rs @@ -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; } diff --git a/crates/egui/src/cache/frame_cache.rs b/crates/egui/src/cache/frame_cache.rs index 6c74c58dc..4c8d25f3e 100644 --- a/crates/egui/src/cache/frame_cache.rs +++ b/crates/egui/src/cache/frame_cache.rs @@ -79,8 +79,4 @@ impl CacheTrait fn len(&self) -> usize { self.cache.len() } - - fn as_any_mut(&mut self) -> &mut dyn std::any::Any { - self - } } diff --git a/crates/egui/src/cache/frame_publisher.rs b/crates/egui/src/cache/frame_publisher.rs index 0c2bc81d6..81ba34df6 100644 --- a/crates/egui/src/cache/frame_publisher.rs +++ b/crates/egui/src/cache/frame_publisher.rs @@ -54,8 +54,4 @@ where fn len(&self) -> usize { self.cache.len() } - - fn as_any_mut(&mut self) -> &mut dyn std::any::Any { - self - } } diff --git a/crates/egui/src/plugin.rs b/crates/egui/src/plugin.rs index d480cc770..6bef04123 100644 --- a/crates/egui/src/plugin.rs +++ b/crates/egui/src/plugin.rs @@ -120,13 +120,13 @@ impl PluginHandle { } fn typed_plugin(&self) -> &P { - (&*self.plugin as &dyn std::any::Any) + (self.plugin.as_ref() as &dyn std::any::Any) .downcast_ref::

() .expect("PluginHandle: plugin is not of the expected type") } pub fn typed_plugin_mut(&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::

() .expect("PluginHandle: plugin is not of the expected type") }