summaryrefslogtreecommitdiff
path: root/graph/src/error.rs
blob: 216268525912e228c53b7cefe4ff10d2a70c0c2b (plain)
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
#![warn(missing_docs)]
//! This file implements the error data type of the graph library.

use std::fmt::{self, Display};

/// The error type for methods of the trait [`Graph`][`super::Graph`].
#[derive(Debug, Clone, PartialEq, Eq, Ord, PartialOrd)]
pub enum Error {
    /// The index is out of bounds.
    ///
    /// The first component is the index that is out of bounds, and
    /// the second component is the current length of nodes.
    IndexOutOfBounds(usize, usize),
}

impl Display for Error {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Error::IndexOutOfBounds(index, len) => {
                write!(f, "index {index} out of bounds {len} ")
            }
        }
    }
}

impl std::error::Error for Error {}