pub struct ClientBuilder { /* private fields */ }Expand description
Fluent builder for Client with optional timeout and other configuration.
Use this instead of the bare Client::new_* constructors when you need to
configure a request timeout.
§Example
use std::time::Duration;
use toolkit_zero::socket::client::{ClientBuilder, Target};
// Async client with a 10-second timeout
let client = ClientBuilder::new(Target::Localhost(8080))
.timeout(Duration::from_secs(10))
.build_async();
// Sync client with a 30-second timeout
let client = ClientBuilder::new(Target::Remote("https://api.example.com".to_string()))
.timeout(Duration::from_secs(30))
.build_sync();Implementations§
Source§impl ClientBuilder
impl ClientBuilder
Sourcepub fn timeout(self, duration: Duration) -> Self
pub fn timeout(self, duration: Duration) -> Self
Set a request timeout.
Both the async and blocking reqwest clients will respect this duration.
Requests that do not complete within the timeout are cancelled and return
a reqwest::Error with is_timeout() = true.
Sourcepub fn build_async(self) -> Client
pub fn build_async(self) -> Client
Build an async-only Client. Safe to call from any context,
including inside #[tokio::main].
Sourcepub fn build_sync(self) -> Client
pub fn build_sync(self) -> Client
Build a sync-only Client.
§Panics
Panics if called from within an async context (same restriction as
reqwest::blocking::Client). See Client::new_sync for details.
Sourcepub fn build(self) -> Client
pub fn build(self) -> Client
Build a client that supports both async and blocking sends.
§Panics
Panics if called from within an async context. See Client::new for details.