use core::future::Future;
use crate::{APIError, AsyncClient, Client};
use bytes::Bytes;
use http::{Response, request::Builder};
pub trait Query<T, C>
where
C: Client,
{
fn request(&self, client: &C) -> Result<Builder, APIError<C::Error>>;
fn send(&self, client: &C, request: Builder) -> Result<Response<Bytes>, APIError<C::Error>>;
fn finalise(&self, response: Response<Bytes>) -> Result<T, APIError<C::Error>>;
fn query(&self, client: &C) -> Result<T, APIError<C::Error>>;
}
pub trait AsyncQuery<T, C>
where
C: AsyncClient,
{
fn request_async(
&self,
client: &C,
) -> impl Future<Output = Result<Builder, APIError<C::Error>>> + Send;
#[cfg(not(target_arch = "wasm32"))]
fn send_async(
&self,
client: &C,
request: Builder,
) -> impl Future<Output = Result<Response<Bytes>, APIError<C::Error>>> + Send;
#[cfg(target_arch = "wasm32")]
fn send_async(
&self,
client: &C,
request: Builder,
) -> impl Future<Output = Result<Response<Bytes>, APIError<C::Error>>>;
fn finalise_async(
&self,
response: Response<Bytes>,
) -> impl Future<Output = Result<T, APIError<C::Error>>> + Send;
#[cfg(not(target_arch = "wasm32"))]
fn query_async(&self, client: &C) -> impl Future<Output = Result<T, APIError<C::Error>>> + Send
where
C::Error: core::error::Error + Sync + Send + 'static;
#[cfg(target_arch = "wasm32")]
fn query_async(&self, client: &C) -> impl Future<Output = Result<T, APIError<C::Error>>>
where
C::Error: core::error::Error + Sync + Send + 'static;
}