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
use std::fmt;
use std::error::Error;

/// Error produced when an indexing operation is out of bounds or otherwise
/// inapplicable.
///
/// Carries no context information (to be as light as possible).
#[derive(Copy, Debug, PartialEq)]
pub struct IndexingError(());

#[inline]
pub fn index_error() -> IndexingError {
    IndexingError(())
}

impl Clone for IndexingError {
    fn clone(&self) -> Self { *self }
}

impl Error for IndexingError {
    fn description(&self) -> &str {
        "index error"
    }
}

impl fmt::Display for IndexingError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        f.write_str(self.description())
    }
}