2023-03-22 22:19:00 +08:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct Error {
|
|
|
|
message: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<std::io::Error> for Error {
|
|
|
|
fn from(err: std::io::Error) -> Self {
|
2023-03-24 14:31:22 +08:00
|
|
|
From::<String>::from(err.to_string())
|
2023-03-22 22:19:00 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-24 09:27:31 +08:00
|
|
|
impl From<std::net::AddrParseError> for Error {
|
|
|
|
fn from(err: std::net::AddrParseError) -> Self {
|
2023-03-24 14:31:22 +08:00
|
|
|
From::<String>::from(err.to_string())
|
2023-03-24 09:27:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<smoltcp::iface::RouteTableFull> for Error {
|
|
|
|
fn from(err: smoltcp::iface::RouteTableFull) -> Self {
|
2023-03-24 14:31:22 +08:00
|
|
|
From::<String>::from(format!("{err:?}"))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<smoltcp::socket::tcp::RecvError> for Error {
|
|
|
|
fn from(err: smoltcp::socket::tcp::RecvError) -> Self {
|
|
|
|
From::<String>::from(format!("{err:?}"))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<smoltcp::socket::tcp::ListenError> for Error {
|
|
|
|
fn from(err: smoltcp::socket::tcp::ListenError) -> Self {
|
|
|
|
From::<String>::from(format!("{err:?}"))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<smoltcp::socket::udp::BindError> for Error {
|
|
|
|
fn from(err: smoltcp::socket::udp::BindError) -> Self {
|
|
|
|
From::<String>::from(format!("{err:?}"))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<smoltcp::socket::tcp::SendError> for Error {
|
|
|
|
fn from(err: smoltcp::socket::tcp::SendError) -> Self {
|
|
|
|
From::<String>::from(format!("{err:?}"))
|
2023-03-24 09:27:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-22 22:19:00 +08:00
|
|
|
impl From<&str> for Error {
|
|
|
|
fn from(err: &str) -> Self {
|
2023-03-24 14:31:22 +08:00
|
|
|
From::<String>::from(err.to_string())
|
2023-03-22 22:19:00 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<String> for Error {
|
|
|
|
fn from(err: String) -> Self {
|
|
|
|
Self { message: err }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<&String> for Error {
|
|
|
|
fn from(err: &String) -> Self {
|
2023-03-24 14:31:22 +08:00
|
|
|
From::<String>::from(err.to_string())
|
2023-03-22 22:19:00 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|