standard_lib/util/
error.rs

1use 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/// TODO
19///
20/// Note: This error is no longer returned by any public part of the API, but it is thrown during
21/// panics. This is because a capacity overflow has such a small chance of occuring that it isn't
22/// worth handling in most placed. Most machines wouldn't have enough memory to overflow a non-ZST
23/// collection with a u64 length.
24#[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 {}