# rust_html A HTML templating library for reusable components in web applications ## About **rust_html** is a tiny templating library that let's you easily create reusable HTML templates and components: ```rust use rust_html::{rhtml, Template}; let card_component = |title: &str| { rhtml! { r#"
{title}
"#} }; let title = "My Website"; let my_template: Template = rhtml! {r#"

{title}

{card_component("Card A")} {card_component("Card B")} {card_component("Card C")}
"#}; let html_string: String = my_template.into(); println!("{}", html_string); ``` ### Why use **rust_html**? - Valid HTML syntax is enforced at compile-time - Runtime rust values are automatically escaped to protect against injection attacks - You can inject any expression or literal (not just identifiers) The library is designed for creating reusable components for SSR (server-side rendering), and is particularly nice in combination with front end libraries like `alpine.js` or `htmx`. Unlike some other templating libraries, you can use the standard HTML syntax directly and keep the templates next to your other Rust code. ## Installation Install from [crates.io](https://crates.io/crates/rust_html) using cargo: ```bash cargo add rust_html ``` ## Usage ### Types The library has only 5 exported functions/types: - `rhtml!`: The main macro for creating templates - `Template`: represents a reusable HTML template - `Render`: trait for implementing reusable `struct` components - `Unescaped`: string wrapper for inserting unescaped values - `TemplateGroup`: wrapper to insert a `Vec