Skip to main content

financial_ops/core/
error.rs

1use std::{
2    error::Error,
3    fmt::{self, Display, Formatter},
4};
5
6/// Represents the possible errors that can occur during decimal operations.
7#[derive(Debug, Clone, Copy, PartialEq, Eq)]
8pub enum DecimalOperationError {
9    /// Indicates that an overflow occurred during the operation.
10    Overflow,
11    /// Indicates that a division by zero occurred during the operation.
12    DivisionByZero,
13}
14
15impl Display for DecimalOperationError {
16    fn fmt(&self, f: &mut Formatter) -> fmt::Result {
17        match self {
18            DecimalOperationError::Overflow => {
19                write!(f, "An overflow occurred during the operation.")
20            }
21            DecimalOperationError::DivisionByZero => {
22                write!(f, "A division by zero occurred during the operation.")
23            }
24        }
25    }
26}
27
28impl Error for DecimalOperationError {}