mirror of
https://github.com/tun2proxy/tun2proxy.git
synced 2025-06-21 00:20:53 +00:00
remove lots of unwrap()
This commit is contained in:
parent
ad388f897a
commit
1d1e50c36a
3 changed files with 164 additions and 150 deletions
44
src/error.rs
44
src/error.rs
|
@ -9,33 +9,49 @@ pub fn s2e(s: &str) -> Error {
|
|||
|
||||
impl From<std::io::Error> for Error {
|
||||
fn from(err: std::io::Error) -> Self {
|
||||
Self {
|
||||
message: err.to_string(),
|
||||
}
|
||||
From::<String>::from(err.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<std::net::AddrParseError> for Error {
|
||||
fn from(err: std::net::AddrParseError) -> Self {
|
||||
Self {
|
||||
message: err.to_string(),
|
||||
}
|
||||
From::<String>::from(err.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<smoltcp::iface::RouteTableFull> for Error {
|
||||
fn from(err: smoltcp::iface::RouteTableFull) -> Self {
|
||||
Self {
|
||||
message: format!("{err:?}"),
|
||||
}
|
||||
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:?}"))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&str> for Error {
|
||||
fn from(err: &str) -> Self {
|
||||
Self {
|
||||
message: err.to_string(),
|
||||
}
|
||||
From::<String>::from(err.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -47,9 +63,7 @@ impl From<String> for Error {
|
|||
|
||||
impl From<&String> for Error {
|
||||
fn from(err: &String) -> Self {
|
||||
Self {
|
||||
message: err.to_string(),
|
||||
}
|
||||
From::<String>::from(err.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue