concision_linear/params/
mode.rs1use concision::Toggle;
6use core::option::Option;
7
8pub trait ParamMode: Toggle {
9 const BIASED: bool = false;
10
11 fn is_biased(&self) -> bool {
12 core::any::TypeId::of::<Self>() == core::any::TypeId::of::<Biased>()
13 }
14
15 private!();
16}
17
18impl<T> ParamMode for Option<T>
23where
24 T: 'static,
25{
26 const BIASED: bool = false;
27
28 fn is_biased(&self) -> bool {
29 self.is_some()
30 }
31
32 seal!();
33}
34
35macro_rules! mode {
36 {$($T:ident: $opt:expr),* $(,)?} => {
37 $(mode!(@impl $T: $opt);)*
38 };
39 (@impl $T:ident: $opt:expr) => {
40 #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
41 #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize,))]
42 pub enum $T {}
43
44 impl Toggle for $T {}
45
46 impl ParamMode for $T {
47 const BIASED: bool = $opt;
48
49 fn is_biased(&self) -> bool {
50 $opt
51 }
52
53 seal!();
54 }
55 };
56
57}
58
59mode! {
60 Biased: true,
61 Unbiased: false,
62}