gliclass/util/
error.rs

1use std::{error::Error, fmt::Display};
2
3/// Input-related error
4#[derive(Debug, Clone)]
5pub struct InputError {
6    message: String,
7}
8
9impl InputError {
10    pub fn new(message: &str) -> Self {
11        Self {
12            message: message.into(),
13        }
14    }
15
16    pub fn into_err<T>(self) -> Result<T, Box<dyn Error + Send + Sync>> {
17        Err(self.boxed())
18    }
19
20    pub fn boxed(self) -> Box<dyn Error + Send + Sync> {
21        Box::new(self)
22    }
23}
24
25impl Error for InputError {}
26
27impl Display for InputError {
28    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
29        f.write_str(&self.message)
30    }
31}