use crate::error::ServerFnError;
use bytes::Bytes;
use futures::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 = "reqwest")]
pub mod reqwest;
pub trait ClientReq<CustErr>
where
Self: Sized,
{
type FormData;
fn try_new_get(
path: &str,
content_type: &str,
accepts: &str,
query: &str,
) -> Result<Self, ServerFnError<CustErr>>;
fn try_new_post(
path: &str,
content_type: &str,
accepts: &str,
body: String,
) -> Result<Self, ServerFnError<CustErr>>;
fn try_new_post_bytes(
path: &str,
content_type: &str,
accepts: &str,
body: Bytes,
) -> Result<Self, ServerFnError<CustErr>>;
fn try_new_post_form_data(
path: &str,
accepts: &str,
content_type: &str,
body: Self::FormData,
) -> Result<Self, ServerFnError<CustErr>>;
fn try_new_multipart(
path: &str,
accepts: &str,
body: Self::FormData,
) -> Result<Self, ServerFnError<CustErr>>;
fn try_new_streaming(
path: &str,
accepts: &str,
content_type: &str,
body: impl Stream<Item = Bytes> + Send + 'static,
) -> Result<Self, ServerFnError<CustErr>>;
}
pub trait Req<CustErr>
where
Self: Sized,
{
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, ServerFnError<CustErr>>> + Send;
fn try_into_string(
self,
) -> impl Future<Output = Result<String, ServerFnError<CustErr>>> + Send;
fn try_into_stream(
self,
) -> Result<
impl Stream<Item = Result<Bytes, ServerFnError>> + Send + 'static,
ServerFnError<CustErr>,
>;
}
pub struct BrowserMockReq;
impl<CustErr> Req<CustErr> for BrowserMockReq
where
CustErr: 'static,
{
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, ServerFnError<CustErr>> {
unreachable!()
}
async fn try_into_string(self) -> Result<String, ServerFnError<CustErr>> {
unreachable!()
}
fn try_into_stream(
self,
) -> Result<
impl Stream<Item = Result<Bytes, ServerFnError>> + Send,
ServerFnError<CustErr>,
> {
Ok(futures::stream::once(async { unreachable!() }))
}
}