Skip to main content

rs_teststand/expression/function/
other.rs

1//! Other expression functions.
2
3/// A other function of the expression language.
4///
5/// Names only: what each one computes is the engine's to document.
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
7pub enum OtherFunction {
8    /// `AllOf`.
9    AllOf,
10    /// `AnyOf`.
11    AnyOf,
12    /// `CheckLimits`.
13    CheckLimits,
14    /// `ConvertColor`.
15    ConvertColor,
16    /// `CurrentUserHasPrivilege`.
17    CurrentUserHasPrivilege,
18    /// `Enum`.
19    Enum,
20    /// `Evaluate`.
21    Evaluate,
22    /// `FindFile`.
23    FindFile,
24    /// `GetEngine`.
25    GetEngine,
26    /// `NoValidation`.
27    NoValidation,
28    /// `OutputMessage`.
29    OutputMessage,
30    /// `RGB`.
31    Rgb,
32    /// `TargetName`.
33    TargetName,
34}
35
36impl OtherFunction {
37    /// Every function in this family.
38    pub const ALL: [Self; 13] = [
39        Self::AllOf,
40        Self::AnyOf,
41        Self::CheckLimits,
42        Self::ConvertColor,
43        Self::CurrentUserHasPrivilege,
44        Self::Enum,
45        Self::Evaluate,
46        Self::FindFile,
47        Self::GetEngine,
48        Self::NoValidation,
49        Self::OutputMessage,
50        Self::Rgb,
51        Self::TargetName,
52    ];
53
54    /// The name as written in an expression.
55    #[must_use]
56    pub const fn name(self) -> &'static str {
57        match self {
58            Self::AllOf => "AllOf",
59            Self::AnyOf => "AnyOf",
60            Self::CheckLimits => "CheckLimits",
61            Self::ConvertColor => "ConvertColor",
62            Self::CurrentUserHasPrivilege => "CurrentUserHasPrivilege",
63            Self::Enum => "Enum",
64            Self::Evaluate => "Evaluate",
65            Self::FindFile => "FindFile",
66            Self::GetEngine => "GetEngine",
67            Self::NoValidation => "NoValidation",
68            Self::OutputMessage => "OutputMessage",
69            Self::Rgb => "RGB",
70            Self::TargetName => "TargetName",
71        }
72    }
73}
74
75#[cfg(test)]
76mod tests {
77    use super::OtherFunction;
78
79    #[test]
80    fn every_name_is_distinct() {
81        let mut names: Vec<&str> = OtherFunction::ALL.iter().map(|f| f.name()).collect();
82        names.sort_unstable();
83        let count = names.len();
84        names.dedup();
85        assert_eq!(names.len(), count);
86    }
87}