governor/
errors.rs

1use std::fmt;
2
3/// Error indicating that the number of cells tested (the first
4/// argument) is larger than the bucket's capacity.
5///
6/// This means the decision can never have a conforming result. The
7/// argument gives the maximum number of cells that could ever have a
8/// conforming result.
9#[derive(Debug, Clone, Copy, PartialEq, Eq)]
10pub struct InsufficientCapacity(pub u32);
11
12impl fmt::Display for InsufficientCapacity {
13    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
14        write!(
15            f,
16            "required number of cells {} exceeds bucket's capacity",
17            self.0
18        )
19    }
20}
21
22#[cfg(feature = "std")]
23impl std::error::Error for InsufficientCapacity {}
24
25#[cfg(all(feature = "std", test))]
26mod test {
27    use super::*;
28
29    #[test]
30    fn coverage() {
31        let display_output = format!("{}", InsufficientCapacity(3));
32        assert!(display_output.contains("3"));
33        let debug_output = format!("{:?}", InsufficientCapacity(3));
34        assert!(debug_output.contains("3"));
35        assert_eq!(InsufficientCapacity(3), InsufficientCapacity(3));
36    }
37}