c3_inheritance/errors.rs
1use std::fmt::{self, Display, Formatter};
2
3/// A type alias for the result of a linearization.
4pub type LinearizeResult<T> = std::result::Result<T, LinearizeError>;
5
6/// A virtual inheritance.
7#[derive(Debug, Clone)]
8pub enum LinearizeError {
9 /// The input class was not found in the graph.
10 NotFound {
11 /// The name of the class that was not found.
12 base: String,
13 },
14 /// The input class was found, but it was not the head of any sequence.
15 BadHead {
16 /// The name of the class that was not the head of any sequence.
17 base: String,
18 /// The name of the class that was the head of the sequence.
19 this: String,
20 },
21 /// A circular dependency was found in the graph.
22 Circular {
23 /// The names of the classes that were involved in the circular dependency.
24 class: String,
25 },
26}
27
28impl Display for LinearizeError {
29 fn fmt(&self, f: &mut Formatter) -> fmt::Result {
30 match self {
31 LinearizeError::NotFound { .. } => write!(f, "cannot find C3-linearization for input"),
32 LinearizeError::BadHead { .. } => write!(f, "cannot find C3-linearization for input"),
33 LinearizeError::Circular { .. } => write!(f, "Circular dependency found"),
34 }
35 }
36}