1use std::error::Error;
16use std::fmt::{Debug, Display, Formatter};
17
18#[derive(Debug)]
19pub enum ContractError {
20 DAGWouldCycle,
21}
22
23impl Display for ContractError {
24 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
25 match self {
26 ContractError::DAGWouldCycle => fmt_dag_would_cycle(f),
27 }
28 }
29}
30
31impl Error for ContractError {}
32
33#[derive(Debug)]
34pub enum ContractSimpleError<E: Error> {
35 DAGWouldCycle,
36 MergeError(E),
37}
38
39impl<E: Error> Display for ContractSimpleError<E> {
40 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
41 match self {
42 ContractSimpleError::DAGWouldCycle => fmt_dag_would_cycle(f),
43 ContractSimpleError::MergeError(ref e) => fmt_merge_error(f, e),
44 }
45 }
46}
47
48impl<E: Error> Error for ContractSimpleError<E> {}
49
50fn fmt_dag_would_cycle(f: &mut Formatter<'_>) -> std::fmt::Result {
51 write!(f, "The operation would introduce a cycle.")
52}
53
54fn fmt_merge_error<E: Error>(f: &mut Formatter<'_>, inner: &E) -> std::fmt::Result {
55 write!(f, "The merge callback failed with: {:?}", inner)
56}
57
58#[derive(Debug, PartialEq, Eq)]
60pub struct LayersError(pub String);
61
62impl Error for LayersError {}
63
64impl Display for LayersError {
65 fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
66 write!(f, "{}", self.0)
67 }
68}