use super::*;
#[cfg(feature = "_async")]
use super::bootstrap::retry_with_config_async;
#[cfg(feature = "_blocking")]
use super::bootstrap::retry_with_config_blocking;
#[cfg(feature = "_async")]
#[derive(Clone)]
pub struct TypedApi {
client: Client,
}
#[cfg(feature = "_async")]
impl TypedApi {
pub(crate) fn new(client: Client) -> Self {
Self { client }
}
pub async fn call<Q>(&self, request: &Q) -> Result<Q::Response>
where
Q: AdvancedRequest,
{
self.client.call_method(Q::METHOD, request).await
}
pub async fn call_with_retry<Q>(&self, request: &Q, retry: RetryConfig) -> Result<Q::Response>
where
Q: AdvancedRequest,
{
retry_with_config_async(&retry, || async {
self.client.call_method(Q::METHOD, request).await
})
.await
}
}
#[cfg(feature = "_blocking")]
#[derive(Clone)]
pub struct BlockingTypedApi {
client: BlockingClient,
}
#[cfg(feature = "_blocking")]
impl BlockingTypedApi {
pub(crate) fn new(client: BlockingClient) -> Self {
Self { client }
}
pub fn call<Q>(&self, request: &Q) -> Result<Q::Response>
where
Q: AdvancedRequest,
{
self.client.call_method(Q::METHOD, request)
}
pub fn call_with_retry<Q>(&self, request: &Q, retry: RetryConfig) -> Result<Q::Response>
where
Q: AdvancedRequest,
{
retry_with_config_blocking(&retry, || self.client.call_method(Q::METHOD, request))
}
}