#[cfg(feature = "actix")]
pub mod actix;
#[cfg(feature = "browser")]
pub mod browser;
#[cfg(feature = "axum-no-default")]
pub mod http;
#[cfg(feature = "reqwest")]
pub mod reqwest;
use crate::error::ServerFnError;
use bytes::Bytes;
use futures::Stream;
use std::future::Future;
pub trait Res<CustErr>
where
Self: Sized,
{
fn try_from_string(
content_type: &str,
data: String,
) -> Result<Self, ServerFnError<CustErr>>;
fn try_from_bytes(
content_type: &str,
data: Bytes,
) -> Result<Self, ServerFnError<CustErr>>;
fn try_from_stream(
content_type: &str,
data: impl Stream<Item = Result<Bytes, ServerFnError<CustErr>>>
+ Send
+ 'static,
) -> Result<Self, ServerFnError<CustErr>>;
fn error_response(path: &str, err: &ServerFnError<CustErr>) -> Self;
fn redirect(&mut self, path: &str);
}
pub trait ClientRes<CustErr> {
fn try_into_string(
self,
) -> impl Future<Output = Result<String, ServerFnError<CustErr>>> + Send;
fn try_into_bytes(
self,
) -> impl Future<Output = Result<Bytes, ServerFnError<CustErr>>> + Send;
fn try_into_stream(
self,
) -> Result<
impl Stream<Item = Result<Bytes, ServerFnError>> + Send + Sync + 'static,
ServerFnError<CustErr>,
>;
fn status(&self) -> u16;
fn status_text(&self) -> String;
fn location(&self) -> String;
fn has_redirect(&self) -> bool;
}
pub struct BrowserMockRes;
impl<CustErr> Res<CustErr> for BrowserMockRes {
fn try_from_string(
_content_type: &str,
_data: String,
) -> Result<Self, ServerFnError<CustErr>> {
unreachable!()
}
fn try_from_bytes(
_content_type: &str,
_data: Bytes,
) -> Result<Self, ServerFnError<CustErr>> {
unreachable!()
}
fn error_response(_path: &str, _err: &ServerFnError<CustErr>) -> Self {
unreachable!()
}
fn try_from_stream(
_content_type: &str,
_data: impl Stream<Item = Result<Bytes, ServerFnError<CustErr>>>,
) -> Result<Self, ServerFnError<CustErr>> {
unreachable!()
}
fn redirect(&mut self, _path: &str) {
unreachable!()
}
}