1
2#[derive(Debug)]
7pub struct IntegerDeltaError(pub(crate) IntegerDeltaErrorImpl);
8
9#[derive(Debug)]
12pub(crate) enum IntegerDeltaErrorImpl {
13 Conversion(isize),
15
16 Sub(usize, usize),
18
19 InvalidNonZero
21}
22
23#[cfg(not(feature = "no_std"))]
24impl std::error::Error for IntegerDeltaError {}
25
26mod fmt {
27 use super::*;
28 use std::fmt;
29
30 impl fmt::Display for IntegerDeltaError {
31 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
32 match self.0 {
33 IntegerDeltaErrorImpl::Conversion(del) => write!(
34 f,
35 "Offset could not be stored (offset of {} is too large)",
36 del
37 ),
38 IntegerDeltaErrorImpl::Sub(a, b) => {
39 write!(f, "Difference is beween {} and {} overflows `isize`", a, b)
40 },
41
42 IntegerDeltaErrorImpl::InvalidNonZero => {
43 write!(f, "Difference was zero when a `NonZero*` type was specified")
44 }
45 }
46 }
47 }
48}