Skip to main content

use_oxidation_state/
oxidation_sign.rs

1use std::fmt;
2
3/// The sign of an oxidation-state value.
4#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
5pub enum OxidationSign {
6    /// A positive oxidation state.
7    Positive,
8    /// A negative oxidation state.
9    Negative,
10    /// A zero oxidation state.
11    Zero,
12}
13
14impl OxidationSign {
15    /// Returns `true` for [`Self::Positive`].
16    #[must_use]
17    pub const fn is_positive(self) -> bool {
18        matches!(self, Self::Positive)
19    }
20
21    /// Returns `true` for [`Self::Negative`].
22    #[must_use]
23    pub const fn is_negative(self) -> bool {
24        matches!(self, Self::Negative)
25    }
26
27    /// Returns `true` for [`Self::Zero`].
28    #[must_use]
29    pub const fn is_zero(self) -> bool {
30        matches!(self, Self::Zero)
31    }
32}
33
34impl fmt::Display for OxidationSign {
35    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
36        match self {
37            Self::Positive => formatter.write_str("+"),
38            Self::Negative => formatter.write_str("-"),
39            Self::Zero => formatter.write_str("0"),
40        }
41    }
42}