use std::fmt;
use std::ops::Deref;
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub(crate) struct Html(String);
pub(crate) static NOTHING: Html = Html(String::new());
impl Html {
pub(crate) fn trusted(markup: impl Into<String>) -> Self {
Self(markup.into())
}
}
impl FromIterator<Html> for Html {
fn from_iter<I: IntoIterator<Item = Html>>(parts: I) -> Self {
Self(parts.into_iter().map(|h| h.0).collect())
}
}
impl Deref for Html {
type Target = str;
fn deref(&self) -> &str {
&self.0
}
}
impl fmt::Display for Html {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&self.0)
}
}
impl askama::filters::HtmlSafe for Html {}
impl From<Html> for String {
fn from(h: Html) -> Self {
h.0
}
}
pub(crate) trait Render {
fn html(&self) -> Html;
}
impl<T: askama::Template> Render for T {
fn html(&self) -> Html {
match self.render() {
Ok(s) => Html(s),
Err(e) => panic!("rendering {}: {e}", std::any::type_name::<T>()),
}
}
}