new const trait syntax
This commit is contained in:
27
src/layout/data.rs
Normal file
27
src/layout/data.rs
Normal file
@@ -0,0 +1,27 @@
|
||||
use std::any::{Any, TypeId};
|
||||
|
||||
use crate::util::{HashMap, Id};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct UiData {
|
||||
map: HashMap<TypeId, Box<dyn Any>>,
|
||||
}
|
||||
|
||||
impl UiData {
|
||||
pub fn get<T: 'static>(&self) -> Option<&T> {
|
||||
self.map
|
||||
.get(&TypeId::of::<T>())
|
||||
.map(|d| d.downcast_ref().unwrap())
|
||||
}
|
||||
pub fn get_mut<T: 'static>(&mut self) -> Option<&mut T> {
|
||||
self.map
|
||||
.get_mut(&TypeId::of::<T>())
|
||||
.map(|d| d.downcast_mut().unwrap())
|
||||
}
|
||||
|
||||
pub fn emit_remove(&mut self, id: &Id) {
|
||||
for (tid, f) in &mut self.on_remove {
|
||||
let data = self.map.get_mut(tid).unwrap().downcast_ref().unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user