use bytes::Bytes;
use futures::{Sink, Stream};
use std::{borrow::Cow, future::Future};
#[cfg(feature = "actix")]
pub mod actix;
#[cfg(feature = "axum-no-default")]
pub mod axum;
#[cfg(feature = "browser")]
pub mod browser;
#[cfg(feature = "generic")]
pub mod generic;
#[cfg(feature = "reqwest")]
pub mod reqwest;
pub trait ClientReq<E>
where
Self: Sized,
{
type FormData;
fn try_new_get(
path: &str,
content_type: &str,
accepts: &str,
query: &str,
) -> Result<Self, E>;
fn try_new_post(
path: &str,
content_type: &str,
accepts: &str,
body: String,
) -> Result<Self, E>;
fn try_new_post_bytes(
path: &str,
content_type: &str,
accepts: &str,
body: Bytes,
) -> Result<Self, E>;
fn try_new_post_form_data(
path: &str,
accepts: &str,
content_type: &str,
body: Self::FormData,
) -> Result<Self, E>;
fn try_new_multipart(
path: &str,
accepts: &str,
body: Self::FormData,
) -> Result<Self, E>;
fn try_new_streaming(
path: &str,
accepts: &str,
content_type: &str,
body: impl Stream<Item = Bytes> + Send + 'static,
) -> Result<Self, E>;
}
pub trait Req<E>
where
Self: Sized,
{
type WebsocketResponse: Send;
fn as_query(&self) -> Option<&str>;
fn to_content_type(&self) -> Option<Cow<'_, str>>;
fn accepts(&self) -> Option<Cow<'_, str>>;
fn referer(&self) -> Option<Cow<'_, str>>;
fn try_into_bytes(self) -> impl Future<Output = Result<Bytes, E>> + Send;
fn try_into_string(self) -> impl Future<Output = Result<String, E>> + Send;
fn try_into_stream(
self,
) -> Result<impl Stream<Item = Result<Bytes, E>> + Send + 'static, E>;
#[allow(clippy::type_complexity)]
fn try_into_websocket(
self,
) -> impl Future<
Output = Result<
(
impl Stream<Item = Result<Bytes, E>> + Send + 'static,
impl Sink<Result<Bytes, E>> + Send + 'static,
Self::WebsocketResponse,
),
E,
>,
> + Send;
}
pub struct BrowserMockReq;
impl<E: Send + 'static> Req<E> for BrowserMockReq {
type WebsocketResponse = crate::response::BrowserMockRes;
fn as_query(&self) -> Option<&str> {
unreachable!()
}
fn to_content_type(&self) -> Option<Cow<'_, str>> {
unreachable!()
}
fn accepts(&self) -> Option<Cow<'_, str>> {
unreachable!()
}
fn referer(&self) -> Option<Cow<'_, str>> {
unreachable!()
}
async fn try_into_bytes(self) -> Result<Bytes, E> {
unreachable!()
}
async fn try_into_string(self) -> Result<String, E> {
unreachable!()
}
fn try_into_stream(
self,
) -> Result<impl Stream<Item = Result<Bytes, E>> + Send, E> {
Ok(futures::stream::once(async { unreachable!() }))
}
async fn try_into_websocket(
self,
) -> Result<
(
impl Stream<Item = Result<Bytes, E>> + Send + 'static,
impl Sink<Result<Bytes, E>> + Send + 'static,
Self::WebsocketResponse,
),
E,
> {
#[allow(unreachable_code)]
Err::<
(
futures::stream::Once<std::future::Ready<Result<Bytes, E>>>,
futures::sink::Drain<Result<Bytes, E>>,
Self::WebsocketResponse,
),
_,
>(unreachable!())
}
}