use crate::states::StateInstance;
use rustc_hash::FxHashMap;
use std::any::{Any, TypeId};
use std::fmt::Debug;
#[derive(Debug, Default)]
pub struct ArgsMap {
cache: FxHashMap<TypeId, Box<dyn Any + Sync + Send>>,
}
impl ArgsMap {
pub fn get<T: Any + Send + Sync>(&self) -> Option<&T> {
if let Some(value) = self.cache.get(&TypeId::of::<T>()) {
return value.downcast_ref::<T>();
}
None
}
pub fn set<T: Any + Send + Sync>(&mut self, args: T) -> &mut Self {
self.cache.insert(TypeId::of::<T>(), Box::new(args));
self
}
}
#[derive(Debug)]
pub struct ExecuteArgs(pub ArgsMap);
impl StateInstance for ExecuteArgs {
fn extract<T: Any + Send + Sync>(&self) -> Option<&T> {
self.0.get::<T>()
}
}