Skip to main content

use_reaction/
reaction_arrow.rs

1use std::fmt;
2
3use crate::ReactionDirection;
4
5/// A reaction arrow style.
6#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
7pub enum ReactionArrow {
8    /// Forward reaction arrow.
9    #[default]
10    Forward,
11    /// Reverse reaction arrow.
12    Reverse,
13    /// Reversible reaction arrow.
14    Reversible,
15    /// Equilibrium reaction arrow.
16    Equilibrium,
17}
18
19impl ReactionArrow {
20    /// Returns the lightweight direction label for this arrow.
21    #[must_use]
22    pub const fn direction(self) -> ReactionDirection {
23        match self {
24            Self::Forward => ReactionDirection::Forward,
25            Self::Reverse => ReactionDirection::Reverse,
26            Self::Reversible => ReactionDirection::Reversible,
27            Self::Equilibrium => ReactionDirection::Equilibrium,
28        }
29    }
30
31    /// Returns `true` for reversible or equilibrium arrows.
32    #[must_use]
33    pub const fn is_reversible(self) -> bool {
34        matches!(self, Self::Reversible | Self::Equilibrium)
35    }
36
37    /// Returns `true` for [`Self::Forward`].
38    #[must_use]
39    pub const fn is_forward(self) -> bool {
40        matches!(self, Self::Forward)
41    }
42
43    /// Returns `true` for [`Self::Reverse`].
44    #[must_use]
45    pub const fn is_reverse(self) -> bool {
46        matches!(self, Self::Reverse)
47    }
48}
49
50impl fmt::Display for ReactionArrow {
51    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
52        let value = match self {
53            Self::Forward => "->",
54            Self::Reverse => "<-",
55            Self::Reversible => "<->",
56            Self::Equilibrium => "⇌",
57        };
58
59        formatter.write_str(value)
60    }
61}