use serde::{Deserialize, Serialize}; use std::time::Duration; #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash)] pub enum ProxyProtocol { Http, Https, Socks4, Socks5, } #[derive(Debug, Serialize, Deserialize, Clone)] pub struct Proxy { pub host: String, pub port: u16, pub protocol: ProxyProtocol, pub country: Option, #[serde(skip)] pub last_checked: Option, #[serde(skip)] pub latency: Option, pub is_working: bool, } impl Proxy { pub fn new(host: String, port: u16, protocol: ProxyProtocol) -> Self { Self { host, port, protocol, country: None, last_checked: None, latency: None, is_working: false, } } pub fn to_url(&self) -> String { let proto = match self.protocol { ProxyProtocol::Http => "http", ProxyProtocol::Https => "https", ProxyProtocol::Socks4 => "socks4", ProxyProtocol::Socks5 => "socks5", }; format!("{}://{}:{}", proto, self.host, self.port) } }