1use std::fmt;
2use std::io;
3use std::io::Error as IOError;
4use thiserror::Error;
5pub type JResult<T> = Result<T, Error>;
6
7#[derive(Error, Debug)]
8pub enum Error {
9 #[error("Unexpected: {0}, {1}")]
10 UnexpectIO(String, io::Error),
11 #[error("Unexpected: {0}")]
12 Unexpected(String),
13}
14
15impl From<&str> for Error {
16 fn from(e: &str) -> Self {
17 Error::Unexpected(e.to_string())
18 }
19}
20
21impl From<(&str, io::Error)> for Error {
22 fn from(e: (&str, io::Error)) -> Self {
23 Error::UnexpectIO(e.0.to_string(), e.1)
24 }
25}
26
27impl From<String> for Error {
28 fn from(e: String) -> Self {
29 Error::Unexpected(e)
30 }
31}
32
33impl From<IOError> for Error {
34 fn from(e: IOError) -> Self {
35 Error::Unexpected(e.to_string())
36 }
37}
38
39impl From<Error> for String {
40 fn from(e: Error) -> Self {
41 format!("{}", e)
42 }
43}