1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
    Appellation: kinds <mod>
    Contrib: FL03 <jo3mccain@icloud.com>
*/
use strum::{AsRefStr, EnumCount, EnumIs, EnumIter, EnumString, VariantNames};

pub trait ParamType: ToString {
    fn kind(&self) -> String;
}

impl<T> ParamType for T
where
    T: ToString,
{
    fn kind(&self) -> String {
        self.to_string()
    }
}

#[derive(
    AsRefStr,
    Clone,
    Debug,
    Default,
    EnumCount,
    EnumIs,
    EnumIter,
    EnumString,
    Eq,
    Hash,
    Ord,
    PartialEq,
    PartialOrd,
    VariantNames,
)]
#[non_exhaustive]
#[repr(usize)]
#[cfg_attr(
    feature = "serde",
    derive(serde::Deserialize, serde::Serialize),
    serde(rename_all = "lowercase", tag = "kind")
)]
#[strum(serialize_all = "lowercase")]
pub enum ParamKind {
    #[default]
    Bias,
    Weight,
    Other(String),
}

impl ParamKind {
    pub fn bias() -> Self {
        Self::Bias
    }

    pub fn weight() -> Self {
        Self::Weight
    }

    pub fn other(name: impl ToString) -> Self {
        Self::Other(name.to_string())
    }
}

impl core::fmt::Display for ParamKind {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        let content = match self {
            ParamKind::Bias => "bias",
            ParamKind::Weight => "weight",
            ParamKind::Other(name) => name,
        };
        write!(f, "{}", content)
    }
}