server_fn/response/
mod.rs1#[cfg(feature = "actix")]
3pub mod actix;
4#[cfg(feature = "browser")]
6pub mod browser;
7#[cfg(feature = "generic")]
8pub mod generic;
9#[cfg(feature = "axum-no-default")]
11pub mod http;
12#[cfg(feature = "reqwest")]
14pub mod reqwest;
15
16use bytes::Bytes;
17use futures::Stream;
18use std::future::Future;
19
20pub trait TryRes<E>
22where
23 Self: Sized,
24{
25 fn try_from_string(content_type: &str, data: String) -> Result<Self, E>;
27
28 fn try_from_bytes(content_type: &str, data: Bytes) -> Result<Self, E>;
30
31 fn try_from_stream(
33 content_type: &str,
34 data: impl Stream<Item = Result<Bytes, E>> + Send + 'static,
35 ) -> Result<Self, E>;
36}
37
38pub trait Res {
40 fn error_response(path: &str, err: String) -> Self;
42
43 fn redirect(&mut self, path: &str);
45}
46
47pub trait ClientRes<E> {
49 fn try_into_string(self) -> impl Future<Output = Result<String, E>> + Send;
51
52 fn try_into_bytes(self) -> impl Future<Output = Result<Bytes, E>> + Send;
54
55 fn try_into_stream(
57 self,
58 ) -> Result<impl Stream<Item = Result<Bytes, E>> + Send + Sync + 'static, E>;
59
60 fn status(&self) -> u16;
62
63 fn status_text(&self) -> String;
65
66 fn location(&self) -> String;
68
69 fn has_redirect(&self) -> bool;
71}
72
73pub struct BrowserMockRes;
80
81impl<E> TryRes<E> for BrowserMockRes {
82 fn try_from_string(_content_type: &str, _data: String) -> Result<Self, E> {
83 unreachable!()
84 }
85
86 fn try_from_bytes(_content_type: &str, _data: Bytes) -> Result<Self, E> {
87 unreachable!()
88 }
89
90 fn try_from_stream(
91 _content_type: &str,
92 _data: impl Stream<Item = Result<Bytes, E>>,
93 ) -> Result<Self, E> {
94 unreachable!()
95 }
96}
97
98impl Res for BrowserMockRes {
99 fn error_response(_path: &str, _err: String) -> Self {
100 unreachable!()
101 }
102
103 fn redirect(&mut self, _path: &str) {
104 unreachable!()
105 }
106}