option_operations/
error.rs1#[cfg(feature = "std")]
4use std::{error, fmt};
5
6#[allow(unused)]
8use crate::OptionOperations;
9
10#[derive(Copy, Clone, Debug, Eq, Ord, PartialEq, PartialOrd)]
12pub enum Error {
13 DivisionByZero,
15 Overflow,
17}
18
19impl Error {
20 #[must_use]
22 pub fn is_division_by_zero(&self) -> bool {
23 matches!(self, Error::DivisionByZero)
24 }
25
26 #[must_use]
28 pub fn is_overflow(&self) -> bool {
29 matches!(self, Error::Overflow)
30 }
31}
32
33#[cfg(feature = "std")]
34impl fmt::Display for Error {
35 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
36 match self {
37 Error::DivisionByZero => f.write_str("An Option Operation overflowed"),
38 Error::Overflow => f.write_str("Division by zero attempted with an Option Operation"),
39 }
40 }
41}
42
43#[cfg(feature = "std")]
44impl error::Error for Error {}