use reqwest::{
Client,
Response,
};
use xdid_core::ResolutionError;
use crate::{
ClientError,
Config,
};
#[cfg(not(target_family = "wasm"))] mod native;
#[cfg(target_family = "wasm")] mod web;
const USER_AGENT: &str = concat!("xdid/", env!("CARGO_PKG_VERSION"));
pub fn build(config: &Config) -> Result<Client, ClientError> {
cfg_select! {
target_family = "wasm" => web::build(config),
_ => native::build(config),
}
}
pub async fn read_capped(res: Response, max: u64) -> Result<Vec<u8>, ResolutionError> {
cfg_select! {
target_family = "wasm" => web::read_capped(res, max).await,
_ => native::read_capped(res, max).await,
}
}
pub fn fetch_failed(e: reqwest::Error) -> ResolutionError {
let refusal = cfg_select! {
target_family = "wasm" => None,
_ => native::refusal(&e),
};
refusal.unwrap_or_else(|| ResolutionError::Transport(e.without_url().to_string()))
}