use std::sync::{Arc, PoisonError, RwLock, RwLockWriteGuard}; use anymap::{any::Any, Map}; type SendSyncAnyMap = Map; /// A shared context for server functions. This allows you to pass data between your server and the server functions like authentication session data. #[derive(Clone)] pub struct DioxusServerContext { shared_context: Arc>, } impl Default for DioxusServerContext { fn default() -> Self { Self { shared_context: Arc::new(RwLock::new(SendSyncAnyMap::new())), } } } impl DioxusServerContext { pub fn get(&self) -> Option { self.shared_context.read().ok()?.get::().cloned() } pub fn insert( &mut self, value: T, ) -> Result<(), PoisonError>> { self.shared_context .write() .map(|mut map| map.insert(value)) .map(|_| ()) } }