1use comp_cat_rs::collapse::free_category::FreeCategoryError;
4
5#[derive(Debug)]
7pub enum Error {
8 FreeCategory(FreeCategoryError),
10 WireOutOfBounds {
12 wire_index: usize,
14 allocated: usize,
16 },
17 WireCountMismatch {
19 expected: usize,
21 actual: usize,
23 },
24}
25
26impl core::fmt::Display for Error {
27 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
28 match self {
29 Self::FreeCategory(e) => write!(f, "free category error: {e}"),
30 Self::WireOutOfBounds {
31 wire_index,
32 allocated,
33 } => write!(
34 f,
35 "wire index {wire_index} out of bounds (allocated: {allocated})"
36 ),
37 Self::WireCountMismatch { expected, actual } => {
38 write!(f, "wire count mismatch: expected {expected}, got {actual}")
39 }
40 }
41 }
42}
43
44impl std::error::Error for Error {
45 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
46 match self {
47 Self::FreeCategory(e) => Some(e),
48 Self::WireOutOfBounds { .. } | Self::WireCountMismatch { .. } => None,
49 }
50 }
51}
52
53impl From<FreeCategoryError> for Error {
54 fn from(e: FreeCategoryError) -> Self {
55 Self::FreeCategory(e)
56 }
57}