#[derive(Debug, thiserror::Error)]
pub enum MoneyError {
#[error("Currency mismatch: cannot operate on {left} and {right}")]
CurrencyMismatch {
left: String,
right: String,
},
#[error("Overflow during operation")]
Overflow,
#[error("Invalid amount: {0}")]
InvalidAmount(String),
#[error("Rounding error: {0}")]
Rounding(String),
#[error("Serialization error: {0}")]
Serialization(String),
}
pub type Result<T> = std::result::Result<T, MoneyError>;
impl From<rust_decimal::Error> for MoneyError {
fn from(e: rust_decimal::Error) -> Self {
MoneyError::InvalidAmount(e.to_string())
}
}