hemplate-runtime
Tiny rendering contract for hemplate templates with no target parser dependencies. Requires Rust 1.91 or newer.
[]
= "0.6.0"
Generated code, adapters and this runtime are released together under one version and pinned exactly; traits from different releases are not interchangeable.
Raw HTML and attribute contexts
Raw interpolation {+= value =+} accepts only HtmlValue types such as
TrustedHtml; plain String and &str values do not compile there. Use escaped {+ text +} for text
and {+ child +} for a Hemplate component. Raw interpolation rejects
Hemplate components, even if they also implement HtmlValue.
TrustedHtml::new_unchecked(markup) performs no validation: use it only where
the application vouches for already-produced HTML, or implement HtmlValue
for a sanitizer's safe output type. Raw output is forbidden in attributes.
Whole dynamic URLs use checked Url values, and srcset uses Srcset; other
sensitive attribute contexts require their matching traits. Typed URL and
srcset values must fill the whole attribute. Trusted*::new_unchecked
explicitly bypasses validation and must not receive untrusted input.
Runtime API
This crate contains only the symbols needed at render time on a target device:
the Hemplate trait, the RenderError type, HtmlEscape, and the render
dispatch helpers used by derive-generated code. It has no parser, no
tree-sitter, and no proc-macro code generation, so it compiles for
constrained targets such as wasm32-unknown-unknown.
The context module holds what the derive macro needs for untrusted values in
attributes that are read as code, CSS, a document or a URL: the traits
UrlValue, SrcsetValue, ScriptValue, StyleValue, DocumentValue,
NavigationValue, ResourceValue and AnimationValue, the checked Url and
Srcset, and Trusted<..> values whose new_unchecked constructor marks where
someone vouches for a value. A plain String satisfies none of them. It is
no_std like the rest of the crate.
Applications should normally use the hemplate facade crate, which re-exports
hemplate-runtime unconditionally and optionally enables the derive feature
for #[derive(Hemplate)].
Use hemplate-runtime directly when:
- you are generating templates offline and only need the render contract in the target binary, or
- you are building a target that cannot depend on
hemplate-parserortree-sitter.