Skip to content

Commit

Permalink
use more grace default macro
Browse files Browse the repository at this point in the history
  • Loading branch information
xlfish233 committed Nov 11, 2024
1 parent 3890abe commit ad25193
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions src/client_reqwest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,19 @@ pub struct AsyncApi {
#[builder(into)]
pub api_url: String,

#[cfg(target_arch = "wasm32")]
#[builder(
default = reqwest::ClientBuilder::new()
.build()
.unwrap()
)]
#[builder(default = default_client())]
pub client: reqwest::Client,
}
fn default_client() -> reqwest::Client {
let client_builder = reqwest::ClientBuilder::new();

#[cfg(not(target_arch = "wasm32"))]
#[builder(
default = reqwest::ClientBuilder::new()
.connect_timeout(std::time::Duration::from_secs(10))
.timeout(std::time::Duration::from_secs(500))
.build()
.unwrap()
)]
pub client: reqwest::Client,
}
let client_builder = client_builder
.connect_timeout(std::time::Duration::from_secs(10))
.timeout(std::time::Duration::from_secs(500));

client_builder.build().unwrap()
}
impl AsyncApi {
/// Create a new `AsyncApi`. You can use [`AsyncApi::new_url`] or [`AsyncApi::builder`] for more options.
pub fn new(api_key: &str) -> Self {
Expand Down

0 comments on commit ad25193

Please sign in to comment.