use std::time::Duration;
#[derive(Debug, Clone)]
pub struct FetchOptions {
pub full_history: bool,
pub probe_days: u32,
pub timeout: Duration,
pub max_concurrency: usize,
pub user_agent: String,
}
impl Default for FetchOptions {
fn default() -> Self {
Self {
full_history: false,
probe_days: 30,
timeout: Duration::from_secs(15),
max_concurrency: 10,
user_agent: format!("rs-histver/{}", env!("CARGO_PKG_VERSION")),
}
}
}
impl FetchOptions {
#[must_use]
pub fn new() -> Self {
Self::default()
}
#[must_use]
pub fn full_history(mut self, v: bool) -> Self {
self.full_history = v;
self
}
#[must_use]
pub fn probe_days(mut self, days: u32) -> Self {
self.probe_days = days;
self
}
#[must_use]
pub fn timeout(mut self, d: Duration) -> Self {
self.timeout = d;
self
}
#[must_use]
pub fn max_concurrency(mut self, n: usize) -> Self {
self.max_concurrency = n;
self
}
#[must_use]
pub fn user_agent(mut self, ua: impl Into<String>) -> Self {
self.user_agent = ua.into();
self
}
}
#[derive(Debug, Clone)]
pub struct NetworkConfig {
pub timeout: u64,
pub max_concurrency: usize,
pub user_agent: String,
}
impl From<&FetchOptions> for NetworkConfig {
fn from(opts: &FetchOptions) -> Self {
Self {
timeout: opts.timeout.as_secs(),
max_concurrency: opts.max_concurrency,
user_agent: opts.user_agent.clone(),
}
}
}