mirror of
https://github.com/tun2proxy/tun2proxy.git
synced 2025-05-14 14:02:45 +00:00
TryFrom for ProxyType
This commit is contained in:
parent
18f4689d21
commit
58364580f5
1 changed files with 14 additions and 6 deletions
20
src/args.rs
20
src/args.rs
|
@ -333,12 +333,7 @@ impl ArgProxy {
|
||||||
Some(UserKey::new(username, password))
|
Some(UserKey::new(username, password))
|
||||||
};
|
};
|
||||||
|
|
||||||
let proxy_type = match url.scheme().to_ascii_lowercase().as_str() {
|
let proxy_type = url.scheme().to_ascii_lowercase().as_str().try_into()?;
|
||||||
"socks4" => Ok(ProxyType::Socks4),
|
|
||||||
"socks5" => Ok(ProxyType::Socks5),
|
|
||||||
"http" => Ok(ProxyType::Http),
|
|
||||||
scheme => Err(Error::from(&format!("`{scheme}` is an invalid proxy type"))),
|
|
||||||
}?;
|
|
||||||
|
|
||||||
Ok(ArgProxy {
|
Ok(ArgProxy {
|
||||||
proxy_type,
|
proxy_type,
|
||||||
|
@ -358,6 +353,19 @@ pub enum ProxyType {
|
||||||
None,
|
None,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl TryFrom<&str> for ProxyType {
|
||||||
|
type Error = Error;
|
||||||
|
fn try_from(value: &str) -> Result<Self> {
|
||||||
|
match value {
|
||||||
|
"http" => Ok(ProxyType::Http),
|
||||||
|
"socks4" => Ok(ProxyType::Socks4),
|
||||||
|
"socks5" => Ok(ProxyType::Socks5),
|
||||||
|
"none" => Ok(ProxyType::None),
|
||||||
|
scheme => Err(Error::from(&format!("`{scheme}` is an invalid proxy type"))),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl std::fmt::Display for ProxyType {
|
impl std::fmt::Display for ProxyType {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue