use crate::prelude::*; use anyhow::Result; use assetpath::AssetPath; use std::any::Any; use std::collections::HashMap; use std::sync::{Arc, Mutex, RwLock, Weak}; pub trait FutureStateChange: Fn() -> Result<()> + Send + Sync { fn clone_box<'a>(&self) -> Box where Self: 'a; fn as_fn(&self) -> &(dyn Fn() -> Result<()> + Send + Sync) where Self: Sized, { self } fn as_static(&'static self) -> &'static (dyn Fn() -> Result<()> + Send + Sync + 'static) where Self: Sized, { self } } impl Result<()> + Clone + Send + Sync> FutureStateChange for F { fn clone_box<'a>(&self) -> Box where Self: 'a, { Box::new(self.clone()) } } impl<'a> Clone for Box { fn clone(&self) -> Self { (**self).clone_box() } } struct State { name: String, top_level_gui: Arc, on_activate: RwLock Result<()> + Send + Sync>>>, on_deactivate: RwLock Result<()> + Send + Sync>>>, next_tab: RwLock Result<()> + Send + Sync>>>, previous_tab: RwLock Result<()> + Send + Sync>>>, decline: RwLock Result<()> + Send + Sync>>>, } /// Opaque handle for a State /// only used for updating callbacks #[derive(Clone)] pub struct StateHandle { state: Weak, } impl StateHandle { pub fn update<'a>(&self, update_type: StateUpdateType<'a>) -> Result<()> { self.state.upgrade().unwrap().update(update_type) } } impl GetElement