Skip to main content

termal_alignment/
error.rs

1// SPDX-License-Identifier: MIT
2// Copyright (c) 2025-2026 Thomas Junier
3
4use std::fmt;
5
6#[derive(Debug)]
7pub enum AlignmentError {
8    Io(std::io::Error),
9    Parse { msg: String },
10    InvalidFormat { msg: String },
11}
12
13impl fmt::Display for AlignmentError {
14    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
15        match self {
16            AlignmentError::Io(e) => write!(f, "I/O error: {e}"),
17            AlignmentError::Parse { msg } => write!(f, "Parse error: {msg}"),
18            AlignmentError::InvalidFormat { msg } => write!(f, "Invalid format: {msg}"),
19        }
20    }
21}
22
23impl std::error::Error for AlignmentError {}
24
25impl From<std::io::Error> for AlignmentError {
26    fn from(e: std::io::Error) -> Self {
27        AlignmentError::Io(e)
28    }
29}