pavex/response/body/
html.rs1use std::borrow::Cow;
2
3use bytes::Bytes;
4use http_body_util::Full;
5use mime::TEXT_HTML_UTF_8;
6
7use crate::http::HeaderValue;
8
9use super::TypedBody;
10
11pub struct Html(Bytes);
28
29impl From<String> for Html {
30 fn from(s: String) -> Self {
31 Self(s.into())
32 }
33}
34
35impl From<&'static str> for Html {
36 fn from(s: &'static str) -> Self {
37 Self(Bytes::from_static(s.as_bytes()))
38 }
39}
40
41impl From<Cow<'static, str>> for Html {
42 fn from(s: Cow<'static, str>) -> Self {
43 match s {
44 Cow::Borrowed(s) => s.into(),
45 Cow::Owned(s) => s.into(),
46 }
47 }
48}
49
50impl TypedBody for Html {
51 type Body = Full<Bytes>;
52
53 fn content_type(&self) -> HeaderValue {
54 HeaderValue::from_static(TEXT_HTML_UTF_8.as_ref())
55 }
56
57 fn body(self) -> Self::Body {
58 Full::new(self.0)
59 }
60}