Skip to main content

rs_teststand/expression/function/
time.rs

1//! Time expression functions.
2
3/// A time 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 TimeFunction {
8    /// `Date`.
9    Date,
10    /// `Seconds`.
11    Seconds,
12    /// `Time`.
13    Time,
14}
15
16impl TimeFunction {
17    /// Every function in this family.
18    pub const ALL: [Self; 3] = [Self::Date, Self::Seconds, Self::Time];
19
20    /// The name as written in an expression.
21    #[must_use]
22    pub const fn name(self) -> &'static str {
23        match self {
24            Self::Date => "Date",
25            Self::Seconds => "Seconds",
26            Self::Time => "Time",
27        }
28    }
29}
30
31#[cfg(test)]
32mod tests {
33    use super::TimeFunction;
34
35    #[test]
36    fn every_name_is_distinct() {
37        let mut names: Vec<&str> = TimeFunction::ALL.iter().map(|f| f.name()).collect();
38        names.sort_unstable();
39        let count = names.len();
40        names.dedup();
41        assert_eq!(names.len(), count);
42    }
43}