rustic_jsonrpc/
container.rs1use std::any::{Any, TypeId};
2use std::collections::HashMap;
3
4pub struct Container {
6 map: HashMap<TypeId, Box<dyn Any + Send + Sync>>,
7}
8
9impl Container {
10 pub fn new() -> Self {
12 Self {
13 map: HashMap::new(),
14 }
15 }
16
17 #[inline]
19 pub fn get<T>(&self) -> Option<&T>
20 where
21 T: Send + Sync + 'static,
22 {
23 self.map
24 .get(&TypeId::of::<T>())
25 .map(|v| v.downcast_ref().unwrap())
26 }
27
28 pub fn put<T>(&mut self, value: T) -> Option<Box<T>>
31 where
32 T: Send + Sync + 'static,
33 {
34 self.map
35 .insert(TypeId::of::<T>(), Box::new(value))
36 .map(|v| v.downcast().unwrap())
37 }
38}