movable_ref/
error.rs

1//! Error types
2
3/// An error type for when an integer offset cannot be stored
4#[derive(Debug)]
5pub struct IntegerOffsetError(pub(crate) IntegerOffsetErrorImpl);
6
7/// All types of errors, this is internal and so protected
8/// behind a wrapper struct
9#[derive(Debug)]
10pub(crate) enum IntegerOffsetErrorImpl {
11    /// Failed to convert isize to given integer type
12    Conversion(isize),
13    /// Failed to subtract the two usizes (overflowed isize)
14    Sub(usize, usize),
15}
16
17#[cfg(feature = "std")]
18impl std::error::Error for IntegerOffsetError {}
19
20mod fmt {
21    use super::*;
22    use std::fmt;
23
24    impl fmt::Display for IntegerOffsetError {
25        fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
26            match self.0 {
27                IntegerOffsetErrorImpl::Conversion(del) => write!(
28                    f,
29                    "Offset could not be stored (offset of {} is too large)",
30                    del
31                ),
32                IntegerOffsetErrorImpl::Sub(a, b) => {
33                    write!(f, "Difference is beween {} and {} overflows `isize`", a, b)
34                }
35            }
36        }
37    }
38}