workers-rsx 0.1.0

A JSX-like templating engine for Cloudflare Workers
Documentation
use crate::html_escaping::escape_html;
use crate::Render;
use std::fmt::{Result, Write};

impl Render for String {
    fn render_into<W: Write>(self, writer: &mut W) -> Result {
        escape_html(&self, writer)
    }
}

impl Render for &str {
    fn render_into<W: Write>(self, writer: &mut W) -> Result {
        escape_html(self, writer)
    }
}

impl Render for std::borrow::Cow<'_, str> {
    fn render_into<W: Write>(self, writer: &mut W) -> Result {
        escape_html(&self, writer)
    }
}

/// A raw (unencoded) html string (borrowed)
#[derive(Debug)]
pub struct Raw<'s>(&'s str);

impl<'s> From<&'s str> for Raw<'s> {
    fn from(s: &'s str) -> Self {
        Raw(s)
    }
}

impl<'s> Render for Raw<'s> {
    fn render_into<W: Write>(self, writer: &mut W) -> Result {
        write!(writer, "{}", self.0)
    }
}

/// A raw (unencoded) html string (owned) — used by control flow blocks
#[derive(Debug)]
pub struct RawOwned(pub String);

impl Render for RawOwned {
    fn render_into<W: Write>(self, writer: &mut W) -> Result {
        write!(writer, "{}", self.0)
    }
}