A server-side template and dynamic fragment rendering library for Rust web applications.
What It Does
- Full-Page Rendering: Renders complete HTML documents configured with
<template shadowrootmode="open">Declarative Shadow DOM shells. - Dynamic Fragment Envelopes: Renders targeted HTML partials inside JSON
Envelopepayloads for partial UI updates. - Payload Verification: Signs dynamic payloads using HMAC-SHA256 or Ed25519, and checks received envelopes with
anza::verify_envelope(version, freshness, slot, signature). - Streaming: Helpers for Server-Sent Events (SSE) and WebSocket message formats.
Installation
Add anza to your Cargo.toml:
[]
= "0.6.0"
To enable Axum framework response helpers:
[]
= { = "0.6.0", = ["axum"] }
Usage
1. Initialize Engine
use Arc;
use Setup;
let mut setup = new;
setup.signing = hmac;
let engine = new;
setup.signing = Setup::ed25519("keys/origin.key", "keys/origin.pub")?; signs
with Ed25519 instead (raw 32-byte key files; a missing file is an error). The
default is no signature. Keys are checked in run(): an HMAC secret shorter
than 32 bytes, a private key that is not a 32-byte seed, or a public key that
doesn't match is a CRYPTO error at setup.
Other Setup fields: watch (reload on change, feature watch), fragments
(allowlist of template names and dir/ prefixes for fragments), escape
(HTML-escape {{x}} values) and max_template_bytes (default 1 MiB).
2. Render Full Pages
use Page;
// templates/pages/home.html inside templates/layout/shell.html ({{content}})
let doc = new
.param
.run
.expect;
println!;
3. Render Signed JSON Fragments
use Fragment;
let envelope = new
.param
.run
.expect;
// {"v":2,"slot":"feed","ts":...,"html":"...","sig":"..."}
let json = to_string.unwrap;
4. Axum Integration Example (features = ["axum"])
use Arc;
use ;
use ;
async
Document and Envelope implement IntoResponse (Axum) and Responder
(Actix-web) when the matching feature is on.
Templates
Templates use {{name}} and {{{name}}} placeholders and are parsed once at
startup. By default both insert values as-is, so escape user input first with
anza::escape_html. With setup.escape = true, {{name}} is HTML-escaped and
{{{name}}} stays raw (use {{{content}}} in the shell). Errors display as
[Anza:CODE] message; Error::code() returns the code. Template layout,
rendering rules and signing are in the documentation.
Documentation
- Guide and API reference: https://anzaui.github.io/rust/
- Engine Contract: the behaviour shared by
the Rust, TypeScript and Python engines (envelope format, signature v2, page
resolution, escaping, error codes).
tests/fixtures/holds vendored copies of its golden fixtures. - Changelog
The docs are markdown in docs/ (pages and sidebar in docs/config.toml),
built with anza docs and deployed to GitHub Pages by
.github/workflows/docs.yml. To build them locally you need the
Anza CLI and the anza repo's theme
in .anza/:
ANZA=/path/to/anza
Releasing
Versions are independent of the other engines and of the Anza CLI.
release-please keeps a release
PR open from the conventional commits on main (version bump in Cargo.toml
and this README, plus a CHANGELOG entry).
-
Merge the release PR. release-please tags the commit
v<version>and creates the GitHub release. -
Publish to crates.io from that tag:
License
MIT © 2026 aduki, Labs