pub trait ProxyFetcher: Send + Sync {
// Required method
fn fetch<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = ProxyResult<Vec<Proxy>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
}Expand description
A source that can produce a list of Proxy records asynchronously.
Implement this trait to integrate any proxy source (remote HTTP list,
commercial API, database, file) with load_from_fetcher.
§Example
use async_trait::async_trait;
use stygian_proxy::{Proxy, ProxyType};
use stygian_proxy::fetcher::ProxyFetcher;
use stygian_proxy::error::ProxyResult;
struct MyStaticFetcher;
#[async_trait]
impl ProxyFetcher for MyStaticFetcher {
async fn fetch(&self) -> ProxyResult<Vec<Proxy>> {
Ok(vec![Proxy {
url: "http://192.168.1.1:8080".into(),
proxy_type: ProxyType::Http,
username: None,
password: None,
weight: 1,
tags: vec!["static".into()],
}])
}
}Required Methods§
Sourcefn fetch<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = ProxyResult<Vec<Proxy>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn fetch<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = ProxyResult<Vec<Proxy>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Fetch the current proxy list.
§Errors
Returns ProxyError::FetchFailed if the source is unreachable or
returns malformed data.