1#![cfg_attr(docsrs, feature(doc_cfg))]
10#![deny(missing_docs)]
11
12use std::str::FromStr;
13
14pub use crate::{
15 compound::Compound,
16 element::Element,
17 equation::{Equation, ReactionQuotient},
18};
19
20#[cfg(feature = "balance")]
21#[cfg_attr(docsrs, doc(cfg(feature = "balance")))]
22pub mod balance;
23mod compound;
24mod display;
25mod element;
26mod equation;
27pub mod error;
28mod parse;
29
30pub const AVAGADRO_CONSTANT: f64 = 6.02214e23;
32
33#[derive(Debug, Default, Clone, PartialEq, Eq, PartialOrd, Ord)]
39#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
40pub enum State {
41 Solid,
43 Liquid,
45 Gas,
47 #[default]
49 Aqueous,
50}
51
52impl FromStr for State {
53 type Err = &'static str;
54
55 fn from_str(s: &str) -> Result<Self, Self::Err> {
56 match s {
57 "s" => Ok(Self::Solid),
58 "l" => Ok(Self::Liquid),
59 "g" => Ok(Self::Gas),
60 "aq" => Ok(Self::Aqueous),
61 _ => Err("Invalid state."),
62 }
63 }
64}
65
66#[derive(Debug, Default, Clone, PartialEq, Eq, PartialOrd, Ord)]
71#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
72pub enum Direction {
73 Left,
75 #[default]
77 Right,
78 Reversible,
80}
81
82impl FromStr for Direction {
83 type Err = &'static str;
84
85 fn from_str(s: &str) -> Result<Self, Self::Err> {
86 match s {
87 "<-" => Ok(Self::Left),
88 "->" => Ok(Self::Right),
89 "<->" => Ok(Self::Reversible),
90 _ => Err("Invalid direction."),
91 }
92 }
93}