#compile-time #scripting #dialect #macro #token-based #token-tree

rukt

Simple Rust dialect for token-based compile-time scripting

6 releases

0.2.4 Nov 19, 2024
0.2.3 Nov 18, 2024
0.1.0 Nov 13, 2024

#973 in Rust patterns

Download history 98/week @ 2024-11-08 388/week @ 2024-11-15 39/week @ 2024-11-22 4/week @ 2024-11-29 2/week @ 2024-12-06

479 downloads per month

MIT/Apache

58KB
606 lines

rukt

Test License Crates.io Crates.io Documentation

Rust dialect for token-based compile-time scripting.

use rukt::rukt;

rukt! {
    pub(crate) let operations = {
        add: +,
        sub: -,
        mul: *,
        div: /,
    };
}

rukt! {
    let {$($name:ident: $operator:tt,)*} = operations;
    expand {
        $(
            fn $name(a: u32, b: u32) -> u32 {
                a $operator b
            }
        )*
    }
}

Introduction

Rukt is a subset of Rust where you manipulate tokens instead of values.

It executes entirely at compile-time. It lets you store arbitrary token trees in variables, operate on these token trees using ordinary expressions and control flow, and substitute them anywhere in regular Rust code.

Rukt is designed to be as unsurprising as possible. It ports well-established Rust idioms to the realm of macro_rules using polished syntax you're already used to.

This is a lightweight, no-dependency crate, backed entirely by declarative macros. There's no procedural macro involved. No unstable features.

Documentation

License

Licensed under MIT or Apache-2.0.

No runtime deps