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
use std::fmt::{self, Display, Formatter};

/// Special result type that wraps an OpError
pub type Result<T> = std::result::Result<T, OpError>;

/// An error that occured while running an operation
#[derive(Debug)]
pub enum OpError {
    NoSuchCrate(String),
    CircularDependency(String, String),
}

impl Display for OpError {
    fn fmt(&self, f: &mut Formatter) -> fmt::Result {
        write!(
            f,
            "{}",
            match self {
                Self::NoSuchCrate(n) => format!("No crate `{}` was not found in the workspace", n),
                Self::CircularDependency(a, b) => format!(
                    "Crates `{}` and `{}` share a hard circular dependency.\
                     Operation not possible!",
                    a, b
                ),
            }
        )
    }
}