1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use std::fmt;

/// Error indicating that the number of cells tested (the first
/// argument) is larger than the bucket's capacity.
///
/// This means the decision can never have a conforming result. The
/// argument gives the maximum number of cells that could ever have a
/// conforming result.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct InsufficientCapacity(pub u32);

impl fmt::Display for InsufficientCapacity {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(
            f,
            "required number of cells {} exceeds bucket's capacity",
            self.0
        )
    }
}

#[cfg(feature = "std")]
impl std::error::Error for InsufficientCapacity {}

#[cfg(all(feature = "std", test))]
mod test {
    use super::*;

    #[test]
    fn coverage() {
        let display_output = format!("{}", InsufficientCapacity(3));
        assert!(display_output.contains("3"));
        let debug_output = format!("{:?}", InsufficientCapacity(3));
        assert!(debug_output.contains("3"));
        assert_eq!(InsufficientCapacity(3), InsufficientCapacity(3));
    }
}