| Crates.io | vy |
| lib.rs | vy |
| version | 0.2.0 |
| created_at | 2024-10-15 19:08:29.496998+00 |
| updated_at | 2025-04-26 23:33:25.0347+00 |
| description | A convenient and type-safe HTML templating library. |
| homepage | |
| repository | https://github.com/JonahLund/vy |
| max_upload_size | |
| id | 1409904 |
| size | 12,208 |
A convenient, type-safe HTML templating library for Rust
Create a typical HTML page:
use vy::prelude::*;
fn page(content: impl IntoHtml) -> impl IntoHtml {
(
DOCTYPE,
html!(
head!(
meta!(charset = "UTF-8"),
title!("My Title"),
meta!(
name = "viewport",
content = "width=device-width,initial-scale=1"
),
meta!(name = "description", content = ""),
link!(rel = "icon", href = "favicon.ico")
),
body!(
h1!("My Heading"),
content
)
),
)
}
Key features to note:
key = value syntax.<meta>, <img>, etc.The macro grammar follows this pattern:
element := [attribute],* [content],*
content := expression
attribute := name['?'] '=' expression
name := identifier | text
rustfmt formatting constraints.type and for use string syntax, e.g., "type" = ".." instead of type = "..".? marks optional attributes (e.g., disabled? = Some("")).The macro design balances several constraints:
rustfmt compatibility (requires parenthesis syntax, e.g., div!() instead of div!{}).Escaping is done automatically, but can be opted out by wrapping a type with PreEscaped(..).
vy utilizes a few practices for fast rendering times:
IntoHtml] types without closures.