#![warn(missing_docs)] //! This file implements the error data type of the graph library. use core::fmt::{self, Display}; /// The error type for methods of the trait [`Graph`][`super::Graph`]. #[derive(Debug, Copy, Clone, PartialEq, Eq, Ord, PartialOrd)] #[non_exhaustive] 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), /// The graph does not permit duplicate nodes but encounters a /// repeated node DuplicatedNode, } 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} ") } Error::DuplicatedNode => write!(f, "No duplicate nodes permitted, but found one"), } } } impl std::error::Error for Error {}