use serde::{Deserialize, Serialize};
use crate::utils::errors::{QSError, Result};
#[derive(Serialize, Deserialize, Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum Compounding {
Simple,
Compounded,
Continuous,
SimpleThenCompounded,
CompoundedThenSimple,
}
impl TryFrom<String> for Compounding {
type Error = QSError;
fn try_from(s: String) -> Result<Self> {
match s.as_str() {
"Simple" => Ok(Self::Simple),
"Compounded" => Ok(Self::Compounded),
"Continuous" => Ok(Self::Continuous),
"SimpleThenCompounded" => Ok(Self::SimpleThenCompounded),
"CompoundedThenSimple" => Ok(Self::CompoundedThenSimple),
_ => Err(QSError::InvalidValueErr(format!(
"Invalid compounding: {s}"
))),
}
}
}
impl From<Compounding> for String {
fn from(compounding: Compounding) -> Self {
match compounding {
Compounding::Simple => "Simple".to_string(),
Compounding::Compounded => "Compounded".to_string(),
Compounding::Continuous => "Continuous".to_string(),
Compounding::SimpleThenCompounded => "SimpleThenCompounded".to_string(),
Compounding::CompoundedThenSimple => "CompoundedThenSimple".to_string(),
}
}
}