use super::ProxyConfig;
#[derive(Clone, Debug)]
pub struct ProxyChain {
pub(crate) proxies: Vec<ProxyConfig>,
}
impl ProxyChain {
pub fn new(proxies: Vec<ProxyConfig>) -> Self {
Self { proxies }
}
pub fn single(proxy: ProxyConfig) -> Self {
Self {
proxies: vec![proxy],
}
}
pub fn len(&self) -> usize {
self.proxies.len()
}
pub(crate) fn route_hash(&self) -> u64 {
use std::hash::{Hash, Hasher};
let mut h = std::collections::hash_map::DefaultHasher::new();
for proxy in &self.proxies {
h.write_u64(proxy.route_hash());
}
self.proxies.len().hash(&mut h);
h.finish()
}
pub fn is_empty(&self) -> bool {
self.proxies.is_empty()
}
pub fn first(&self) -> Option<&ProxyConfig> {
self.proxies.first()
}
pub fn iter(&self) -> impl Iterator<Item = &ProxyConfig> {
self.proxies.iter()
}
}