xrune

The Grimoire

One casting, many inscriptions. You speak the rite; the runesmith cuts it into code.

咒成于文,文译于师。一咒既立,万法可镌。

Read the Grimoire Enter the Forge
$cargo add xrune
scroll

IWhat it is

One Casting, Many Inscriptions

Write a casting in xrune's declarative DSL. A runesmith you bind — any type implementing the eight-method DsRune trait — inscribes it into whatever code your host actually needs: ECS spawn calls, a render-tree builder, a debug echo, a formatter round-trip.

The DSL only parses. Widget names are any identifier and attribute values are any Rust expression, so every shred of meaning lives in the rune you bind.

ui! { … }
column {
    title ("Grimoire")
    walk $pages with p {
        page (p) on Tap(open)
    }
}
  • DefaultRunea println! trace of every node
  • miruilive widgets on MCU, desktop, phone, web
  • xrune-fmtthe same casting, re-scribed
  • your runewhatever your host needs

IIThe Ritual

Watch a Casting Compile

One incantation, traced through every form it takes: source, tree, trait calls, code.

seal() → proc_macro2::TokenStream

IIIThe Forge

The Spellbook

Write a casting. The real xrune parser, compiled to WebAssembly, deciphers it on every keystroke, then three runes inscribe it.

The Casting

IVThe Covenant

The Eight Runes

A rune is any type that implements DsRune: eight methods, no defaults. decipher calls one per node; your rune decides what each becomes.

Host it in your own proc-macro

ui! hard-wires DefaultRune. A real backend ships its own proc-macro crate and swaps in its rune; downstream users write the same DSL.

#[proc_macro]
pub fn my_ui(input: TokenStream) -> TokenStream {
    let root = parse_macro_input!(input as DsRoot);
    let mut rune = MyRune::new();
    rune.inscribe_root(&root.get_parent());
    decipher(&root.get_content(), &mut rune);
    TokenStream::from(rune.seal())
}

The one foot-gun

decipher never walks the children it hands you. Every inscribe that receives them must recurse itself. Forget it and the subtree vanishes, without a word.

fn inscribe_widget(&mut self, name: &syn::Ident, /* … */ children: &[DsTreeRef]) {
    /* … emit code for `name` … */
    for child in children {
        decipher(child, self); // omit this and the subtree disappears
    }
}

VIIn the Wild

mirui Speaks xrune

mirui, a Rust UI framework that runs on microcontrollers, desktops, phones and the web, writes its UI in xrune castings. Its ui! macro is a rune.

abridged · source ↗
ui!(compose Card {
    Column (direction: FlexDirection::Column, grow: 1.0) {
        View (bg_color: ColorToken::Primary, height: 32) {
            @@header {
                Text (
                    "(untitled)",
                    text_color: ColorToken::OnPrimary
                )
            }
        }
        View (bg_color: ColorToken::SurfaceVariant, grow: 1.0) {
            @@body {
                Text ("no body yet")
            }
        }
        View (height: 32) {
            @@footer
        }
    }
});
Card (width: Dimension::percent(100), height: 140) {
    @header {
        Text ("ALERT", text_color: ColorToken::OnPrimary)
    }
    @body {
        Text ("@header @body @footer")
        Text ("each pick their own slot.")
    }
    @footer {
        Text ("FOOTER SLOT", font_size: 11)
    }
}
compose Card tap the card to fill or empty it
(untitled) ALERT
no body yet @header @body @footer
each pick their own slot.
empty · no fallback FOOTER SLOT
The Card that casting composes, drawn in place. Watch it run in mirui ↗

VIIThe Choice

When to Reach for It

Plug-in code-gen

One DSL, many runes. The same casting can become spawn calls, a render builder, a static analyzer.

Untyped at parse time

Widget names are arbitrary idents; attribute values are arbitrary syn::Expr. All semantics live in the runesmith you bind.

Built for hosting

Ship your own proc-macro crate, bind your own runesmith, and downstream users write the same DSL with your code-gen.

Need compile-time types on widget names and attribute keys? Reach for a typed-builder DSL such as leptos::view!, dioxus::rsx! or yew::html!. Read the comparison →

Begin the Rite

$cargo add xrune