causal_hub/types/
states.rs1use indexmap::{IndexMap, IndexSet};
2
3pub type Map<K, V> = IndexMap<K, V, FxBuildHasher>;
5pub type Set<T> = IndexSet<T, FxBuildHasher>;
7pub type Labels = Set<String>;
9
10pub use fxhash::FxBuildHasher;
11
12#[macro_export]
14macro_rules! set {
15 [] => { $crate::types::Set::default() };
16 [$($value:expr,)+] => { $crate::set!($($value),+) };
17 [$($value:expr),*] => {
18 {
19 const CAPACITY: usize = <[()]>::len(&[$({ stringify!($value); }),*]);
20 let mut set = $crate::types::Set::with_capacity_and_hasher(
21 CAPACITY,
22 fxhash::FxBuildHasher::default(),
23 );
24 $(
25 set.insert($value);
26 )*
27 set
28 }
29 };
30}
31
32#[macro_export]
34macro_rules! labels {
35 [] => { $crate::types::Labels::default() };
36 [$($label:expr),+ $(,)?] => {
37 {
38 const CAPACITY: usize = <[()]>::len(&[$({ stringify!($label); }),*]);
39 let mut labels = $crate::types::Labels::with_capacity_and_hasher(
40 CAPACITY,
41 fxhash::FxBuildHasher::default(),
42 );
43 $(
44 labels.insert(::std::string::ToString::to_string(&$label));
45 )*
46 labels
47 }
48 };
49}
50
51#[macro_export]
53macro_rules! map {
54 [] => { $crate::types::Map::default() };
55 [$(($key:expr, $value:expr),)+] => { $crate::map!($(($key, $value)),+) };
56 [$(($key:expr, $value:expr)),*] => {
57 {
58 const CAPACITY: usize = <[()]>::len(&[$({ stringify!($key); stringify!($value); }),*]);
59 let mut map = $crate::types::Map::with_capacity_and_hasher(
60 CAPACITY,
61 fxhash::FxBuildHasher::default(),
62 );
63 $(
64 map.insert($key, $value);
65 )*
66 map
67 }
68 };
69}
70
71#[macro_export]
73macro_rules! support {
74 [] => { $crate::models::CatSupport::default() };
75 [$(($label:expr, [$($value:expr),* $(,)?]),)+] => { $crate::support!($(($label, [$($value),*])),+) };
76 [$(($label:expr, [$($value:expr),* $(,)?])),*] => {
77 {
78 const CAPACITY: usize = <[()]>::len(&[$({ stringify!($label); $( stringify!($value); )* }),*]);
79 let mut support: $crate::models::CatSupport = $crate::types::Map::with_capacity_and_hasher(
80 CAPACITY,
81 $crate::types::FxBuildHasher::default(),
82 );
83 $(
84 let label = ::std::string::ToString::to_string(&$label);
86 let value = $crate::set![$(
88 ::std::string::ToString::to_string(&$value)
89 ),*];
90 support.insert(label, value);
92 )*
93 support
94 }
95 };
96}