1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
use std::convert::From; use std::error::Error; use std::string::FromUtf8Error; pub type SdResult<T> = Result<T, ShadowError>; #[derive(Debug)] pub enum ShadowError { String(String), } impl ShadowError { pub fn new(err: impl Error) -> Self { ShadowError::String(err.to_string()) } } impl ToString for ShadowError { fn to_string(&self) -> String { match self { ShadowError::String(e) => e.to_string(), } } } impl From<std::string::FromUtf8Error> for ShadowError { fn from(e: FromUtf8Error) -> Self { ShadowError::String(e.to_string()) } } impl From<std::io::Error> for ShadowError { fn from(e: std::io::Error) -> Self { ShadowError::String(e.to_string()) } } impl From<String> for ShadowError { fn from(e: String) -> Self { ShadowError::String(e) } } impl From<std::env::VarError> for ShadowError { fn from(e: std::env::VarError) -> Self { ShadowError::String(e.to_string()) } } impl From<std::num::ParseIntError> for ShadowError { fn from(e: std::num::ParseIntError) -> Self { ShadowError::String(e.to_string()) } }