data_structures/linked_list/
errors.rs1#[derive(Debug)]
2pub enum Error {
3 PositionOutOfBounds(usize, usize),
4 ElementDoesNotExist,
5}
6
7impl std::fmt::Display for Error {
8 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::result::Result<(), std::fmt::Error> {
9 match self {
10 Error::PositionOutOfBounds(posn, length) => write!(
11 f,
12 "Trying to access at {} but list's length is {}",
13 posn, length
14 ),
15
16 Error::ElementDoesNotExist => write!(f, "Element doesn't exist"),
17 }
18 }
19}
20impl std::error::Error for Error {}