pavex/response/body/
plain_text.rs1use std::borrow::Cow;
2
3use bytes::Bytes;
4use http_body_util::Full;
5
6use crate::http::HeaderValue;
7
8use super::TypedBody;
9
10impl TypedBody for String {
11 type Body = Full<Bytes>;
12
13 fn content_type(&self) -> HeaderValue {
14 HeaderValue::from_static(mime::TEXT_PLAIN_UTF_8.as_ref())
15 }
16
17 fn body(self) -> Self::Body {
18 Full::new(self.into())
19 }
20}
21
22impl TypedBody for &'static str {
23 type Body = Full<Bytes>;
24
25 fn content_type(&self) -> HeaderValue {
26 HeaderValue::from_static(mime::TEXT_PLAIN_UTF_8.as_ref())
27 }
28
29 fn body(self) -> Self::Body {
30 Full::new(self.into())
31 }
32}
33
34impl TypedBody for Cow<'static, str> {
35 type Body = Full<Bytes>;
36
37 fn content_type(&self) -> HeaderValue {
38 HeaderValue::from_static(mime::TEXT_PLAIN_UTF_8.as_ref())
39 }
40
41 fn body(self) -> Self::Body {
42 match self {
43 Cow::Borrowed(s) => s.body(),
44 Cow::Owned(s) => s.body(),
45 }
46 }
47}