standard_lib/util/
error.rs1use std::error::Error;
2use std::fmt::{self, Display, Formatter};
3
4#[derive(Debug)]
5pub struct IndexOutOfBounds {
6 pub index: usize,
7 pub len: usize,
8}
9
10impl Display for IndexOutOfBounds {
11 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
12 write!(f, "Index {} out of bounds for collection with {} elements!", self.index, self.len)
13 }
14}
15
16impl Error for IndexOutOfBounds {}
17
18#[derive(Debug)]
25pub struct CapacityOverflow;
26
27impl Display for CapacityOverflow {
28 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
29 write!(f, "Capacity overflow!")
30 }
31}
32
33impl Error for CapacityOverflow {}
34
35#[derive(Debug)]
36pub struct NoValueForKey;
37
38impl Display for NoValueForKey {
39 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
40 write!(f, "No values is associated with the provided key.")
41 }
42}
43
44impl Error for NoValueForKey {}