use_reaction/
reaction_arrow.rs1use std::fmt;
2
3use crate::ReactionDirection;
4
5#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
7pub enum ReactionArrow {
8 #[default]
10 Forward,
11 Reverse,
13 Reversible,
15 Equilibrium,
17}
18
19impl ReactionArrow {
20 #[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 #[must_use]
33 pub const fn is_reversible(self) -> bool {
34 matches!(self, Self::Reversible | Self::Equilibrium)
35 }
36
37 #[must_use]
39 pub const fn is_forward(self) -> bool {
40 matches!(self, Self::Forward)
41 }
42
43 #[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}