Skip to main content

stdin_helper/
erro.rs

1use std::fmt::Display;
2use std::io;
3use std::error::Error;
4
5#[derive(Debug)]
6pub struct BoolParseError(pub &'static str);
7
8impl Display for BoolParseError {
9    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
10        write!(f, "{}", self.0)
11    }
12}
13
14impl Error for BoolParseError {}
15
16#[derive(Debug)]
17pub enum InputError<E> {
18    Io(io::Error),
19    Parse(E)
20}
21
22
23impl<E: Error> Error for InputError<E>  {}
24
25impl<E: Display> Display for InputError<E>  {
26    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
27        match self {
28            InputError::Io(e) => write!(f, "I/O Error: {e}"),
29            InputError::Parse(e) => write!(f, "Parse Error: {e}")
30        }
31    }
32}
33
34impl<E> From<io::Error> for InputError<E>  {
35    fn from(value: io::Error) -> Self {
36        InputError::Io(value)
37    }
38}