codify "platform" into resolution logic, server-fn/fullstack overhaul (#4596)
overhaul dioxus fullstack using a new implementation of server_fn This PR is a complete rewrite of dioxus fullstack designed to improve compatibility with axum and to fix a number of compilation errors based on feature flag unification plumbing through macros.
This commit is contained in:
1 parent
8421c3aef0
commit
f2b1c6d97f
424 files changed
+17284
-6624
No files matched your search
@@ -0,0 +1,38 @@
|
||||
use crate::{ClientResponse, FromResponse};
|
||||
use axum_core::response::{IntoResponse, Response};
|
||||
use dioxus_fullstack_core::ServerFnError;
|
||||
use send_wrapper::SendWrapper;
|
||||
use std::future::Future;
|
||||
|
||||
/// A simple text response type.
|
||||
///
|
||||
/// The `T` parameter can be anything that converts to and from `String`, such as `Rc<str>` or `String`.
|
||||
///
|
||||
/// Unlike `Json` or plain `String`, this uses the `text/plain` content type. The `text/plain` header
|
||||
/// will be set on the request.
|
||||
pub struct Text<T>(pub T);
|
||||
|
||||
impl<T> Text<T> {
|
||||
/// Create a new text response.
|
||||
pub fn new(text: T) -> Self {
|
||||
Self(text)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Into<String>> IntoResponse for Text<T> {
|
||||
fn into_response(self) -> Response {
|
||||
Response::builder()
|
||||
.header("Content-Type", "text/plain; charset=utf-8")
|
||||
.body(axum_core::body::Body::from(self.0.into()))
|
||||
.unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: From<String>> FromResponse for Text<T> {
|
||||
fn from_response(res: ClientResponse) -> impl Future<Output = Result<Self, ServerFnError>> {
|
||||
SendWrapper::new(async move {
|
||||
let text = res.text().await?;
|
||||
Ok(Text::new(text.into()))
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user