crates.io ↗

iet-ui-macros

tooling tooling official

Compiles the html! macro into straight-line string writes.

CoreFeaturesIntegrationsStacksTooling
Used byiet-ui
iet-ui-macrostoolinghtml! macro
Depends onnothing — it stands alone

How to use it

html! is a function-like macro that parses literal HTML with rstml and expands to straight-line string writes producing an iet_ui::Markup. Static markup is fused into a single buffer allocation, brace-delimited expressions are escaped inline (strings as attributes, Render types and iterators as children), and text! renders escaped formatted text without a temporary buffer. It is re-exported as iet_ui::html.

rust
// crates/features/iet-ui/src/components.rs
use crate::{Markup, html};

pub fn notice(message: &str, error: bool) -> Markup {
    let role = if error { "alert" } else { "status" };
    html! { <div role={role} class="rounded border p-3" aria-live="polite">{text!("{message}")}</div> }
}

pub fn csrf_field(token: &str) -> Markup {
    html! { <input type="hidden" name="csrf" value={token} /> }
}
  • Element and attribute names must be literal HTML; attribute spreads (<div {attrs}>) and attribute bindings are compile errors.
  • Children accept Option<Markup>, iterators of Render, and nested html! { ... }; use text! for formatted, escaped interpolation.
  • .to_string() yields the HTML; .into_string() moves the buffer without copying.

How it works

The proc macro parses the tokens with rstml, then an Emitter accumulates literal HTML into one buffer and expression interpolations into push_str/write_escaped/Render::render_into calls, wrapping the whole expansion in iet_ui::Markup::from_rendered.

flowchart LR
  H["html! tokens"] --> R["rstml parse2"]
  R --> EM["Emitter"]
  EM --> LT["fused literal buffer"]
  EM --> WR["writes for expressions"]
  WR --> WE["write_escaped attributes"]
  WR --> RI["Render render_into children"]
  LT --> OUT["iet_ui Markup from_rendered"]
  WE --> OUT
  RI --> OUT

What it implements

  • Concrete mechanism; see the public API below.

What's inside

Modules

  • src/lib.rs
  • src/render.rs
  • src/script.rs

Public API

(root)

  • pub fn script(input: proc_macro::TokenStream) -> proc_macro::TokenStream
  • pub fn static_view(input: proc_macro::TokenStream) -> proc_macro::TokenStream
  • pub fn html(input: proc_macro::TokenStream) -> proc_macro::TokenStream

render

  • pub fn expand(input: TokenStream) -> syn::Result<TokenStream>
  • pub fn expand_static(input: TokenStream) -> syn::Result<TokenStream>

script

  • pub fn expand(input: TokenStream) -> syn::Result<TokenStream>

Depends on

  • No other framework crate: it stands alone.

External crates: oxc_allocator, oxc_parser, oxc_span, proc-macro2, quote, rstml, sha2, syn

Cargo features

  • scripts — dep:oxc_allocator, dep:oxc_parser, dep:oxc_span, dep:sha2

Used by

In this repository

  • Not used by a checked-in example yet.

Source: crates/macros/iet-ui-macros