docs_configuration/
docs_configuration.rs

1//! Documentation examples for Configuration page.
2//!
3//! Run with: cargo run --example docs_configuration
4
5use std::{num::NonZeroU32, time::Duration};
6
7use http::uri::Scheme;
8use s2_sdk::{
9    S2,
10    types::{BasinAuthority, RetryConfig, S2Config, S2Endpoints},
11};
12
13fn main() -> Result<(), Box<dyn std::error::Error>> {
14    // Example: Custom endpoints (e.g., for s2-lite local dev)
15    {
16        let token = "local-token".to_string();
17        // ANCHOR: custom-endpoints
18        let endpoints = S2Endpoints::new(
19            "localhost:8080".parse()?,
20            BasinAuthority::Direct("localhost:8080".parse()?),
21        )
22        .with_scheme(Scheme::HTTP);
23
24        let client = S2::new(S2Config::new(token).with_endpoints(endpoints))?;
25        // ANCHOR_END: custom-endpoints
26        println!("Created client with custom endpoints: {:?}", client);
27    }
28
29    // Example: Custom retry configuration
30    {
31        let token = std::env::var("S2_ACCESS_TOKEN").unwrap_or_else(|_| "demo".into());
32        // ANCHOR: retry-config
33        let client = S2::new(
34            S2Config::new(token).with_retry(
35                RetryConfig::new()
36                    .with_max_attempts(NonZeroU32::new(5).unwrap())
37                    .with_min_base_delay(Duration::from_millis(100))
38                    .with_max_base_delay(Duration::from_secs(2)),
39            ),
40        )?;
41        // ANCHOR_END: retry-config
42        println!("Created client with retry config: {:?}", client);
43    }
44
45    // Example: Custom timeout configuration
46    {
47        let token = std::env::var("S2_ACCESS_TOKEN").unwrap_or_else(|_| "demo".into());
48        // ANCHOR: timeout-config
49        let client = S2::new(
50            S2Config::new(token)
51                .with_connection_timeout(Duration::from_secs(5))
52                .with_request_timeout(Duration::from_secs(10)),
53        )?;
54        // ANCHOR_END: timeout-config
55        println!("Created client with timeout config: {:?}", client);
56    }
57
58    Ok(())
59}