use std::error::Error;
use std::fmt;
use use_stoichiometry::StoichiometryValidationError;
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum ReactionValidationError {
EmptyReaction,
MissingReactants,
MissingProducts,
EmptyCatalystLabel,
EmptySolventLabel,
EmptyTemperatureLabel,
EmptyPressureLabel,
EmptyConditionLabel,
EmptyConditionValue,
InvalidStoichiometry(StoichiometryValidationError),
}
impl fmt::Display for ReactionValidationError {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::EmptyReaction => {
formatter.write_str("reaction must contain reactants and products")
},
Self::MissingReactants => {
formatter.write_str("reaction must contain at least one reactant")
},
Self::MissingProducts => {
formatter.write_str("reaction must contain at least one product")
},
Self::EmptyCatalystLabel => formatter.write_str("catalyst label must not be empty"),
Self::EmptySolventLabel => formatter.write_str("solvent label must not be empty"),
Self::EmptyTemperatureLabel => {
formatter.write_str("temperature label must not be empty")
},
Self::EmptyPressureLabel => formatter.write_str("pressure label must not be empty"),
Self::EmptyConditionLabel => formatter.write_str("condition label must not be empty"),
Self::EmptyConditionValue => formatter.write_str("condition value must not be empty"),
Self::InvalidStoichiometry(error) => {
write!(formatter, "invalid stoichiometry: {error}")
},
}
}
}
impl Error for ReactionValidationError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
match self {
Self::InvalidStoichiometry(error) => Some(error),
_ => None,
}
}
}
impl From<StoichiometryValidationError> for ReactionValidationError {
fn from(error: StoichiometryValidationError) -> Self {
Self::InvalidStoichiometry(error)
}
}