use crate::str_types::SafeHtmlStr;
pub trait SafeHtmlPart {
fn write_to<W: core::fmt::Write>(&self, w: &mut W) -> core::fmt::Result;
}
impl SafeHtmlPart for &str {
fn write_to<W: core::fmt::Write>(&self, w: &mut W) -> core::fmt::Result {
crate::escape_html_and_coerce_to(self, w)
}
}
impl SafeHtmlPart for char {
fn write_to<W: core::fmt::Write>(&self, w: &mut W) -> core::fmt::Result {
let mut tmp = [0; 4];
crate::escape_html_and_coerce_to(self.encode_utf8(&mut tmp), w)
}
}
impl SafeHtmlPart for &SafeHtmlStr {
fn write_to<W: core::fmt::Write>(&self, w: &mut W) -> core::fmt::Result {
w.write_str(self.as_str())
}
}
impl SafeHtmlPart for &crate::IdentifierStr {
fn write_to<W: core::fmt::Write>(&self, w: &mut W) -> core::fmt::Result {
w.write_str(self.as_str())
}
}
macro_rules! impl_safe_html_part_for_display {
($($t:ty)*) => {
$(
impl SafeHtmlPart for $t {
fn write_to<W: core::fmt::Write>(&self, w: &mut W) -> core::fmt::Result {
write!(w, "{}", self)
}
}
)*
};
}
impl_safe_html_part_for_display!(i8 i16 i32 i64 i128 isize u8 u16 u32 u64 u128 usize f32 f64 bool);
#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
impl SafeHtmlPart for alloc::string::String {
fn write_to<W: core::fmt::Write>(&self, w: &mut W) -> core::fmt::Result {
crate::escape_html_and_coerce_to(self.as_str(), w)
}
}
#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
impl SafeHtmlPart for crate::types::SafeHtml {
fn write_to<W: core::fmt::Write>(&self, w: &mut W) -> core::fmt::Result {
w.write_str(self.as_str())
}
}
#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
impl SafeHtmlPart for &crate::types::SafeHtml {
fn write_to<W: core::fmt::Write>(&self, w: &mut W) -> core::fmt::Result {
w.write_str(self.as_str())
}
}
#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
impl SafeHtmlPart for crate::types::Identifier {
fn write_to<W: core::fmt::Write>(&self, w: &mut W) -> core::fmt::Result {
w.write_str(self.as_str())
}
}
#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
impl SafeHtmlPart for &crate::types::Identifier {
fn write_to<W: core::fmt::Write>(&self, w: &mut W) -> core::fmt::Result {
w.write_str(self.as_str())
}
}
impl SafeHtmlPart for &crate::SafeUrlStr {
fn write_to<W: core::fmt::Write>(&self, w: &mut W) -> core::fmt::Result {
crate::escape_html_and_coerce_to(self.as_str(), w)
}
}
impl SafeHtmlPart for &crate::TrustedResourceUrlStr {
fn write_to<W: core::fmt::Write>(&self, w: &mut W) -> core::fmt::Result {
crate::escape_html_and_coerce_to(self.as_str(), w)
}
}
#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
impl SafeHtmlPart for crate::types::SafeUrl {
fn write_to<W: core::fmt::Write>(&self, w: &mut W) -> core::fmt::Result {
crate::escape_html_and_coerce_to(self.as_str(), w)
}
}
#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
impl SafeHtmlPart for &crate::types::SafeUrl {
fn write_to<W: core::fmt::Write>(&self, w: &mut W) -> core::fmt::Result {
crate::escape_html_and_coerce_to(self.as_str(), w)
}
}
#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
impl SafeHtmlPart for crate::types::TrustedResourceUrl {
fn write_to<W: core::fmt::Write>(&self, w: &mut W) -> core::fmt::Result {
crate::escape_html_and_coerce_to(self.as_str(), w)
}
}
#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
impl SafeHtmlPart for &crate::types::TrustedResourceUrl {
fn write_to<W: core::fmt::Write>(&self, w: &mut W) -> core::fmt::Result {
crate::escape_html_and_coerce_to(self.as_str(), w)
}
}