Skip to main content

zotero_api_rs/client/
config.rs

1//! Client construction options.
2
3use std::time::Duration;
4
5/// Retry behavior for transient API failures.
6#[derive(Clone, Copy, Debug)]
7pub struct RetryPolicy {
8    /// Total attempts including the first request.
9    pub max_attempts: u32,
10    /// Base exponential backoff delay.
11    pub base_delay: Duration,
12    /// Maximum backoff delay.
13    pub max_delay: Duration,
14}
15
16impl Default for RetryPolicy {
17    fn default() -> Self {
18        Self {
19            max_attempts: 3,
20            base_delay: Duration::from_millis(200),
21            max_delay: Duration::from_secs(5),
22        }
23    }
24}
25
26/// Options used to create a [`crate::client::ZoteroClient`].
27#[derive(Clone, Debug)]
28pub struct ClientOptions {
29    /// API endpoint root.
30    pub base_url: String,
31    /// Optional authentication.
32    pub auth: Option<crate::client::Auth>,
33    /// Total request timeout.
34    pub timeout: Duration,
35    /// Connection establishment timeout.
36    pub connect_timeout: Duration,
37    /// `User-Agent` value.
38    pub user_agent: String,
39    /// Retry policy.
40    pub retry_policy: RetryPolicy,
41}
42
43impl Default for ClientOptions {
44    fn default() -> Self {
45        Self {
46            base_url: "https://api.zotero.org/".to_owned(),
47            auth: None,
48            timeout: Duration::from_secs(30),
49            connect_timeout: Duration::from_secs(10),
50            user_agent: format!("zotero-rs/{}", env!("CARGO_PKG_VERSION")),
51            retry_policy: RetryPolicy::default(),
52        }
53    }
54}