From 31e8d4791e09a53076b7ce004c12ee2d5ca9d6a0 Mon Sep 17 00:00:00 2001 From: ssrlive <30760636+ssrlive@users.noreply.github.com> Date: Fri, 24 Mar 2023 16:32:47 +0800 Subject: [PATCH] remove s2e function --- src/error.rs | 4 ---- src/lib.rs | 14 +++++++------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/error.rs b/src/error.rs index b7ecc3b..4bd7f1d 100644 --- a/src/error.rs +++ b/src/error.rs @@ -3,10 +3,6 @@ pub struct Error { message: String, } -pub fn s2e(s: &str) -> Error { - Error::from(s) -} - impl From for Error { fn from(err: std::io::Error) -> Self { From::::from(err.to_string()) diff --git a/src/lib.rs b/src/lib.rs index b09ee97..0779247 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,4 @@ -use crate::error::{s2e, Error}; +use crate::error::Error; use crate::tun2proxy::{Credentials, Options}; use crate::{http::HttpManager, socks5::Socks5Manager, tun2proxy::TunToProxy}; use std::net::{SocketAddr, ToSocketAddrs}; @@ -20,21 +20,21 @@ pub struct Proxy { impl Proxy { pub fn from_url(s: &str) -> Result { let e = format!("`{s}` is not a valid proxy URL"); - let url = url::Url::parse(s).map_err(|_| s2e(&e))?; + let url = url::Url::parse(s).map_err(|_| Error::from(&e))?; let e = format!("`{s}` does not contain a host"); - let host = url.host_str().ok_or(s2e(&e))?; + let host = url.host_str().ok_or(Error::from(e))?; let mut url_host = String::from(host); let e = format!("`{s}` does not contain a port"); - let port = url.port().ok_or(s2e(&e))?; + let port = url.port().ok_or(Error::from(&e))?; url_host.push(':'); url_host.push_str(port.to_string().as_str()); let e = format!("`{host}` could not be resolved"); - let mut addr_iter = url_host.to_socket_addrs().map_err(|_| s2e(&e))?; + let mut addr_iter = url_host.to_socket_addrs().map_err(|_| Error::from(&e))?; let e = format!("`{host}` does not resolve to a usable IP address"); - let addr = addr_iter.next().ok_or(s2e(&e))?; + let addr = addr_iter.next().ok_or(Error::from(&e))?; let credentials = if url.username() == "" && url.password().is_none() { None @@ -51,7 +51,7 @@ impl Proxy { "http" => Some(ProxyType::Http), _ => None, } - .ok_or(s2e(&format!("`{scheme}` is an invalid proxy type")))?; + .ok_or(Error::from(&format!("`{scheme}` is an invalid proxy type")))?; Ok(Proxy { proxy_type,