Skip to main content

use_ion/
charge_sign.rs

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