Last active: a year ago
#[derive(Debug, Clone, PartialEq)]
pub enum NodeType {
VMESS,
VLESS,
SS,
SSR,
TROJAN,
TROJANGO,
HTTPPROXY,
HTTPSPROXY,
SOCKS5,
HTTP2,
UNKNOWN,
}
impl From<&str> for NodeType {
fn from(value: &str) -> Self {
use NodeType::*;
match value {
"vmess" => VMESS,
"vless" => VLESS,
"ss" => SS,
"ssr" => SSR,
"trojan" => TROJAN,
"trojan-go" => TROJANGO,
"http-proxy" => HTTPPROXY,
"https-proxy" => HTTPSPROXY,
"socks5" => SOCKS5,
"http2" => HTTP2,
_ => UNKNOWN,
}
}
}
impl NodeType {
pub fn as_str(&self) -> &str {
use NodeType::*;
match self {
VMESS => "vmess",
VLESS => "vless",
SS => "ss",
SSR => "ssr",
TROJAN => "trojan",
TROJANGO => "trojan-go",
HTTPPROXY => "http-proxy",
HTTPSPROXY => "https-proxy",
SOCKS5 => "socks5",
HTTP2 => "http2",
UNKNOWN => "unknown",
}
}
}
impl Serialize for NodeType {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_str(self.as_str())
}
}
impl<'de> Deserialize<'de> for NodeType {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let s = String::deserialize(deserializer)?;
Ok(NodeType::from(s.as_str()))
}
}