Skip to main content

workers_rsx/
text_element.rs

1use crate::html_escaping::escape_html;
2use crate::Render;
3use std::fmt::{Result, Write};
4
5impl Render for String {
6    fn render_into<W: Write>(self, writer: &mut W) -> Result {
7        escape_html(&self, writer)
8    }
9}
10
11impl Render for &str {
12    fn render_into<W: Write>(self, writer: &mut W) -> Result {
13        escape_html(self, writer)
14    }
15}
16
17impl Render for std::borrow::Cow<'_, str> {
18    fn render_into<W: Write>(self, writer: &mut W) -> Result {
19        escape_html(&self, writer)
20    }
21}
22
23/// A raw (unencoded) html string (borrowed)
24#[derive(Debug)]
25pub struct Raw<'s>(&'s str);
26
27impl<'s> From<&'s str> for Raw<'s> {
28    fn from(s: &'s str) -> Self {
29        Raw(s)
30    }
31}
32
33impl<'s> Render for Raw<'s> {
34    fn render_into<W: Write>(self, writer: &mut W) -> Result {
35        write!(writer, "{}", self.0)
36    }
37}
38
39/// A raw (unencoded) html string (owned) — used by control flow blocks
40#[derive(Debug)]
41pub struct RawOwned(pub String);
42
43impl Render for RawOwned {
44    fn render_into<W: Write>(self, writer: &mut W) -> Result {
45        write!(writer, "{}", self.0)
46    }
47}