yozefu_tui/
error.rs

1use lib::Error;
2use std::{
3    fmt::{self, Display, Formatter},
4    num::TryFromIntError,
5};
6use tokio::sync::mpsc::error::SendError;
7
8/// Wrapper of around the `lib::Error` struct.
9//#[derive(Debug)]
10pub struct TuiError(Error);
11
12impl<T> From<SendError<T>> for TuiError {
13    fn from(e: SendError<T>) -> Self {
14        TuiError(Error::Error(e.to_string()))
15    }
16}
17
18impl Display for TuiError {
19    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
20        write!(f, "{}", self.0)
21    }
22}
23
24use std::fmt::Debug;
25
26impl Debug for TuiError {
27    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
28        write!(f, "{}", self.0)
29    }
30}
31
32impl From<&str> for TuiError {
33    fn from(e: &str) -> Self {
34        TuiError(Error::Error(e.to_string()))
35    }
36}
37
38impl From<serde_json::Error> for TuiError {
39    fn from(e: serde_json::Error) -> Self {
40        TuiError(Error::SerdeError(e))
41    }
42}
43
44impl From<Error> for TuiError {
45    fn from(e: Error) -> Self {
46        TuiError(e)
47    }
48}
49
50impl From<TuiError> for Error {
51    fn from(val: TuiError) -> Self {
52        val.0
53    }
54}
55
56impl From<std::io::Error> for TuiError {
57    fn from(e: std::io::Error) -> Self {
58        TuiError(Error::IoError(e))
59    }
60}
61
62impl From<TryFromIntError> for TuiError {
63    fn from(e: TryFromIntError) -> Self {
64        TuiError(Error::Error(e.to_string()))
65    }
66}