use std::collections::{HashMap, HashSet}; use crate::proxy::{Proxy, ProxyType}; pub(crate) struct ProxyStorage { proxies: HashSet, enabled_protocols: HashSet, } impl ProxyStorage { pub(crate) fn new(protocols: HashSet) -> Self { Self { proxies: HashSet::new(), enabled_protocols: protocols } } pub(crate) fn insert(&mut self, proxy: Proxy) { if self.enabled_protocols.contains(&proxy.protocol) { self.proxies.insert(proxy); } } pub(crate) fn get_grouped(&self) -> HashMap> { let mut groups: HashMap> = self .enabled_protocols .iter() .map(|p| (p.clone(), Vec::new())) .collect(); for proxy in &self.proxies { groups.entry(proxy.protocol.clone()).or_default().push(proxy); } groups } pub(crate) fn iter(&self) -> std::collections::hash_set::Iter<'_, Proxy> { self.proxies.iter() } } impl IntoIterator for ProxyStorage { type IntoIter = std::collections::hash_set::IntoIter; type Item = Proxy; fn into_iter(self) -> Self::IntoIter { self.proxies.into_iter() } }