dioxus_fullstack/payloads/
text.rs1use crate::{ClientResponse, FromResponse};
2use axum_core::response::{IntoResponse, Response};
3use dioxus_fullstack_core::ServerFnError;
4use send_wrapper::SendWrapper;
5use std::future::Future;
6
7pub struct Text<T>(pub T);
14
15impl<T> Text<T> {
16 pub fn new(text: T) -> Self {
18 Self(text)
19 }
20}
21
22impl<T: Into<String>> IntoResponse for Text<T> {
23 fn into_response(self) -> Response {
24 Response::builder()
25 .header("Content-Type", "text/plain; charset=utf-8")
26 .body(axum_core::body::Body::from(self.0.into()))
27 .unwrap()
28 }
29}
30
31impl<T: From<String>> FromResponse for Text<T> {
32 fn from_response(res: ClientResponse) -> impl Future<Output = Result<Self, ServerFnError>> {
33 SendWrapper::new(async move {
34 let text = res.text().await?;
35 Ok(Text::new(text.into()))
36 })
37 }
38}