Skip to main content

graphrecords_query/error/
arithmetic.rs

1use crate::Diagnostic;
2use graphrecords_core::graphrecord::GraphRecordValue;
3use std::{
4    error::Error,
5    fmt::{self, Display, Formatter},
6};
7
8#[derive(Debug)]
9pub struct DivisionByZero {
10    dividend: GraphRecordValue,
11}
12
13impl DivisionByZero {
14    #[must_use]
15    pub const fn new(dividend: GraphRecordValue) -> Self {
16        Self { dividend }
17    }
18
19    #[must_use]
20    pub const fn dividend(&self) -> &GraphRecordValue {
21        &self.dividend
22    }
23}
24
25impl Display for DivisionByZero {
26    fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
27        write!(formatter, "cannot divide `{}` by zero", self.dividend)
28    }
29}
30
31impl Error for DivisionByZero {}
32
33impl Diagnostic for DivisionByZero {
34    fn name() -> &'static str {
35        "DivisionByZero"
36    }
37}
38
39#[derive(Debug)]
40pub struct ModuloByZero;
41
42impl Display for ModuloByZero {
43    fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
44        formatter.write_str("cannot calculate a remainder with a zero modulus")
45    }
46}
47
48impl Error for ModuloByZero {}
49
50impl Diagnostic for ModuloByZero {
51    fn name() -> &'static str {
52        "ModuloByZero"
53    }
54}