tui_lib/
tui_errors.rs

1use std::{error::Error, fmt::Display};
2
3#[derive(Clone, Debug)]
4pub struct CError {
5    pub error_string: String,
6}
7impl From<String> for CError {
8    fn from(value: String) -> CError {
9        return CError {
10            error_string: value,
11        };
12    }
13}
14impl From<&str> for CError {
15    fn from(value: &str) -> CError {
16        return CError {
17            error_string: value.into(),
18        };
19    }
20}
21
22impl Display for CError {
23    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
24        return f.write_str(&self.error_string);
25    }
26}
27impl Error for CError {}
28
29#[derive(Clone, Copy, Debug)]
30pub struct IOError {}
31
32impl Display for IOError {
33    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
34        return f.write_str("IO Error");
35    }
36}
37impl Error for IOError {}
38#[derive(Clone, Copy, Debug)]
39pub struct OverflowError {}
40
41impl Display for OverflowError {
42    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
43        return f.write_str("Overflow");
44    }
45}
46impl Error for OverflowError {}
47#[derive(Clone, Copy, Debug)]
48pub struct TuiUnexpectedInputError {
49    pub expected: char,
50    pub recieved: char,
51}
52
53impl Display for TuiUnexpectedInputError {
54    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
55        let result = "Expected: ".to_string()
56            + &self.expected.to_string()
57            + "\nGot: "
58            + &self.recieved.to_string();
59        return f.write_str(&result);
60    }
61}
62impl Error for TuiUnexpectedInputError {}