Skip to main content

calendar_types/
primitive.rs

1//! Primitive types not belonging to a specific area.
2
3/// A numeric sign, which may be either positive or negative.
4#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
5#[repr(i8)]
6pub enum Sign {
7    /// Negative sign (`-`).
8    Neg = -1,
9    /// Positive sign (`+`).
10    #[default]
11    Pos = 1,
12}
13
14impl Sign {
15    /// Returns the ASCII character representation of this sign (`'+'` or `'-'`).
16    pub const fn as_char(self) -> char {
17        match self {
18            Sign::Neg => '-',
19            Sign::Pos => '+',
20        }
21    }
22}
23
24#[cfg(test)]
25mod tests {
26    use super::*;
27
28    #[test]
29    fn sign_ord_impl() {
30        assert!(Sign::Neg < Sign::Pos);
31    }
32}