use bincode::Error as bincode_e; use hyper::Error as hyper_e; use sled::Error as sled_e; use std::fmt; use std::net::AddrParseError; use std::num::ParseIntError; #[derive(Debug)] pub struct TwinHError(pub String); impl TwinHError { fn bail(self) {} } impl std::error::Error for TwinHError {} impl std::fmt::Display for TwinHError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { write!(f, "twinh: {}", self.0) } } impl From for TwinHError { fn from(e: sled_e) -> Self { Self(format!("database error: {}", e)) } } impl From for TwinHError { fn from(e: bincode_e) -> Self { Self(format!("(de)serialization error: {}", e)) } } impl From for TwinHError { fn from(e: AddrParseError) -> Self { Self(format!("failed to parse addr: {}", e)) } } impl From for TwinHError { fn from(e: ParseIntError) -> Self { Self(format!("failed to parse port: {}", e)) } } impl From for TwinHError { fn from(e: hyper_e) -> Self { Self(format!("server error: {}", e)) } }