use std::borrow::Cow;
use bytes::Bytes;
use http_body_util::Full;
use mime::TEXT_HTML_UTF_8;
use crate::http::HeaderValue;
use super::TypedBody;
pub struct Html(Bytes);
impl From<String> for Html {
fn from(s: String) -> Self {
Self(s.into())
}
}
impl From<&'static str> for Html {
fn from(s: &'static str) -> Self {
Self(Bytes::from_static(s.as_bytes()))
}
}
impl From<Cow<'static, str>> for Html {
fn from(s: Cow<'static, str>) -> Self {
match s {
Cow::Borrowed(s) => s.into(),
Cow::Owned(s) => s.into(),
}
}
}
impl TypedBody for Html {
type Body = Full<Bytes>;
fn content_type(&self) -> HeaderValue {
HeaderValue::from_static(TEXT_HTML_UTF_8.as_ref())
}
fn body(self) -> Self::Body {
Full::new(self.0)
}
}