remove s2e function

This commit is contained in:
ssrlive 2023-03-24 16:32:47 +08:00
parent 0fd5d85155
commit 31e8d4791e
2 changed files with 7 additions and 11 deletions

View file

@ -3,10 +3,6 @@ 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 {
From::<String>::from(err.to_string())

View file

@ -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<Proxy, Error> {
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,