Skip to main content

use_stoichiometry/
reaction_side.rs

1use std::fmt;
2
3/// A reaction-side label.
4#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
5pub enum ReactionSide {
6    /// Reactant side.
7    Reactant,
8    /// Product side.
9    Product,
10}
11
12impl ReactionSide {
13    /// Returns `true` for [`Self::Reactant`].
14    #[must_use]
15    pub const fn is_reactant(self) -> bool {
16        matches!(self, Self::Reactant)
17    }
18
19    /// Returns `true` for [`Self::Product`].
20    #[must_use]
21    pub const fn is_product(self) -> bool {
22        matches!(self, Self::Product)
23    }
24}
25
26impl fmt::Display for ReactionSide {
27    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
28        match self {
29            Self::Reactant => formatter.write_str("reactant"),
30            Self::Product => formatter.write_str("product"),
31        }
32    }
33}