Keywords
How each of Program's keywords is rendered into Rust.
Contents
How a Program becomes Rust, in parts. Start with the introduction, then follow each part into the rendered output and the runtime it links against.
- Introduction — what the Rust target is, and how to read the rest of this section.
- Capabilities — which high-level features are possible, built in or through a crate.
- Example — a full program using every keyword, and the Rust it renders to.
- Naming considerations — how Program's dotted names are carried into Rust.
- Entry point — starting a program from
mainwith its drivers. - Drivers — the native drivers that provide the interface, console and network.
- Runtime — the Reactive and Context machinery the rendered code links against.
- Native modules — the hand-written Rust behind
NATIVEfunctions. - Keywords — how each of Program's keywords renders to Rust.
- Project setup — the files and commands to build and run the rendered program.
- Reserved words — the words Rust keeps for itself, and how a colliding name is escaped.
Program keywords in Rust
Each of Program's keywords maps to idiomatic Rust. Names nest through mods joined with
:: (see the example); the reactive
keywords are calls into the runtime. Follow a keyword's own page for the full rendering and the
other targets.
| Keyword | Rendered Rust |
|---|---|
MODULE | A nested mod, snake_case — Ui.Button.Integer becomes ui::button::integer. |
TYPE | A record becomes pub struct Point { pub x: f64, pub y: f64 }; a union becomes pub enum Shape { Circle(Circle), Rect(Rect) }. |
FUNCTION | pub fn Name(…) -> ReactiveValue<T> { … }. |
NATIVE | A pub fn whose body is the rust NATIVE string. |
INPUT | A parameter; a BINDING input is read and written. |
HOLE | A Box<dyn Fn(…)> callback parameter. |
LET | let name = …;. |
STATE | let name = Reactive::state::<T>(value);. |
REVERSE | A write-back whose closing SET is Reactive::set(state, value). |
WITH | module::with(name, replacement, Box::new(move || { … })). |
See JavaScript keywords for the per-keyword detail and the modifiers; Rust differs in idiom (snake_case modules, boxed closures) but the mapping is the same.