peace_rt_model_core/params/
workspace_params.rs1use std::{
2 hash::Hash,
3 marker::PhantomData,
4 ops::{Deref, DerefMut},
5};
6
7use serde::Serialize;
8use type_reg::untagged::{BoxDt, TypeMap};
9
10#[derive(Clone, Debug, Serialize)]
24#[serde(transparent)] pub struct WorkspaceParams<K>(TypeMap<K, BoxDt>, PhantomData<K>)
26where
27 K: Eq + Hash;
28
29impl<K> WorkspaceParams<K>
30where
31 K: Eq + Hash,
32{
33 pub fn new() -> Self {
35 Self::default()
36 }
37
38 pub fn with_capacity(capacity: usize) -> Self {
43 Self(TypeMap::with_capacity_typed(capacity), PhantomData)
44 }
45
46 pub fn into_inner(self) -> TypeMap<K, BoxDt> {
48 self.0
49 }
50}
51
52impl<K> Default for WorkspaceParams<K>
53where
54 K: Eq + Hash,
55{
56 fn default() -> Self {
57 Self(TypeMap::default(), PhantomData)
58 }
59}
60
61impl<K> Deref for WorkspaceParams<K>
62where
63 K: Eq + Hash,
64{
65 type Target = TypeMap<K, BoxDt>;
66
67 fn deref(&self) -> &Self::Target {
68 &self.0
69 }
70}
71
72impl<K> DerefMut for WorkspaceParams<K>
73where
74 K: Eq + Hash,
75{
76 fn deref_mut(&mut self) -> &mut Self::Target {
77 &mut self.0
78 }
79}
80
81impl<K> From<TypeMap<K, BoxDt>> for WorkspaceParams<K>
82where
83 K: Eq + Hash,
84{
85 fn from(type_map: TypeMap<K, BoxDt>) -> Self {
86 Self(type_map, PhantomData)
87 }
88}