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:
10
crates/egui/src/cache/cache_storage.rs
vendored
10
crates/egui/src/cache/cache_storage.rs
vendored
@@ -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()
|
||||
}
|
||||
|
||||
4
crates/egui/src/cache/cache_trait.rs
vendored
4
crates/egui/src/cache/cache_trait.rs
vendored
@@ -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;
|
||||
}
|
||||
|
||||
4
crates/egui/src/cache/frame_cache.rs
vendored
4
crates/egui/src/cache/frame_cache.rs
vendored
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
4
crates/egui/src/cache/frame_publisher.rs
vendored
4
crates/egui/src/cache/frame_publisher.rs
vendored
@@ -54,8 +54,4 @@ where
|
||||
fn len(&self) -> usize {
|
||||
self.cache.len()
|
||||
}
|
||||
|
||||
fn as_any_mut(&mut self) -> &mut dyn std::any::Any {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user