committed by
B. Blechschmidt
2 changed files with 28 additions and 53 deletions
@ -1,76 +1,50 @@ |
|||||
#[derive(Debug)] |
#[derive(thiserror::Error, Debug)] |
||||
pub struct Error { |
pub enum Error { |
||||
message: String, |
#[error("std::io::Error {0}")] |
||||
} |
IoError(#[from] std::io::Error), |
||||
|
|
||||
impl From<std::io::Error> for Error { |
#[error("std::net::AddrParseError {0}")] |
||||
fn from(err: std::io::Error) -> Self { |
AddrParseError(#[from] std::net::AddrParseError), |
||||
From::<String>::from(err.to_string()) |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
impl From<std::net::AddrParseError> for Error { |
#[error("smoltcp::iface::RouteTableFull {0:?}")] |
||||
fn from(err: std::net::AddrParseError) -> Self { |
RouteTableFull(#[from] smoltcp::iface::RouteTableFull), |
||||
From::<String>::from(err.to_string()) |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
impl From<smoltcp::iface::RouteTableFull> for Error { |
#[error("smoltcp::socket::tcp::RecvError {0:?}")] |
||||
fn from(err: smoltcp::iface::RouteTableFull) -> Self { |
RecvError(#[from] smoltcp::socket::tcp::RecvError), |
||||
From::<String>::from(format!("{err:?}")) |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
impl From<smoltcp::socket::tcp::RecvError> for Error { |
#[error("smoltcp::socket::tcp::ListenError {0:?}")] |
||||
fn from(err: smoltcp::socket::tcp::RecvError) -> Self { |
ListenError(#[from] smoltcp::socket::tcp::ListenError), |
||||
From::<String>::from(format!("{err:?}")) |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
impl From<smoltcp::socket::tcp::ListenError> for Error { |
#[error("smoltcp::socket::udp::BindError {0:?}")] |
||||
fn from(err: smoltcp::socket::tcp::ListenError) -> Self { |
BindError(#[from] smoltcp::socket::udp::BindError), |
||||
From::<String>::from(format!("{err:?}")) |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
impl From<smoltcp::socket::udp::BindError> for Error { |
#[error("smoltcp::socket::tcp::SendError {0:?}")] |
||||
fn from(err: smoltcp::socket::udp::BindError) -> Self { |
SendError(#[from] smoltcp::socket::tcp::SendError), |
||||
From::<String>::from(format!("{err:?}")) |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
impl From<smoltcp::socket::tcp::SendError> for Error { |
#[error("&str {0}")] |
||||
fn from(err: smoltcp::socket::tcp::SendError) -> Self { |
Str(String), |
||||
From::<String>::from(format!("{err:?}")) |
|
||||
} |
#[error("String {0}")] |
||||
|
String(String), |
||||
|
|
||||
|
#[error("&String {0}")] |
||||
|
RefString(String), |
||||
} |
} |
||||
|
|
||||
impl From<&str> for Error { |
impl From<&str> for Error { |
||||
fn from(err: &str) -> Self { |
fn from(err: &str) -> Self { |
||||
From::<String>::from(err.to_string()) |
Self::Str(err.to_string()) |
||||
} |
} |
||||
} |
} |
||||
|
|
||||
impl From<String> for Error { |
impl From<String> for Error { |
||||
fn from(err: String) -> Self { |
fn from(err: String) -> Self { |
||||
Self { message: err } |
Self::String(err) |
||||
} |
} |
||||
} |
} |
||||
|
|
||||
impl From<&String> for Error { |
impl From<&String> for Error { |
||||
fn from(err: &String) -> Self { |
fn from(err: &String) -> Self { |
||||
From::<String>::from(err.to_string()) |
Self::RefString(err.to_string()) |
||||
} |
|
||||
} |
|
||||
|
|
||||
impl std::fmt::Display for Error { |
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { |
|
||||
write!(f, "{}", self.message) |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
impl std::error::Error for Error { |
|
||||
fn description(&self) -> &str { |
|
||||
&self.message |
|
||||
} |
} |
||||
} |
} |
||||
|
|||||
Loading…
Reference in new issue