mirror of
https://github.com/tun2proxy/tun2proxy.git
synced 2025-06-20 16:10:52 +00:00
move error handler to a separate module
This commit is contained in:
parent
5cbb13247f
commit
e637a55e6a
5 changed files with 90 additions and 64 deletions
50
src/error.rs
Normal file
50
src/error.rs
Normal file
|
@ -0,0 +1,50 @@
|
|||
#[derive(Debug)]
|
||||
pub struct Error {
|
||||
message: String,
|
||||
}
|
||||
|
||||
pub fn s2e(s: &str) -> Error {
|
||||
Error::from(s)
|
||||
}
|
||||
|
||||
impl From<std::io::Error> for Error {
|
||||
fn from(err: std::io::Error) -> Self {
|
||||
Self {
|
||||
message: err.to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&str> for Error {
|
||||
fn from(err: &str) -> Self {
|
||||
Self {
|
||||
message: err.to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<String> for Error {
|
||||
fn from(err: String) -> Self {
|
||||
Self { message: err }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&String> for Error {
|
||||
fn from(err: &String) -> Self {
|
||||
Self {
|
||||
message: 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…
Add table
Add a link
Reference in a new issue