use std::error::Error;
use std::fmt::{Debug, Display, Formatter};
#[derive(Debug)]
pub enum ContractError {
DAGWouldCycle,
}
impl Display for ContractError {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
ContractError::DAGWouldCycle => fmt_dag_would_cycle(f),
}
}
}
impl Error for ContractError {}
#[derive(Debug)]
pub enum ContractSimpleError<E: Error> {
DAGWouldCycle,
MergeError(E),
}
impl<E: Error> Display for ContractSimpleError<E> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
ContractSimpleError::DAGWouldCycle => fmt_dag_would_cycle(f),
ContractSimpleError::MergeError(ref e) => fmt_merge_error(f, e),
}
}
}
impl<E: Error> Error for ContractSimpleError<E> {}
fn fmt_dag_would_cycle(f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "The operation would introduce a cycle.")
}
fn fmt_merge_error<E: Error>(f: &mut Formatter<'_>, inner: &E) -> std::fmt::Result {
write!(f, "The merge callback failed with: {:?}", inner)
}
#[derive(Debug, PartialEq, Eq)]
pub struct LayersError(pub String);
impl Error for LayersError {}
impl Display for LayersError {
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}