UI!: JSX-style template syntax with compile-time checksBeam: Component System based on Rust structs
Features
- Supports client component via island architecture in Wasm. (See Client Component section below)
- Simply organized API and codebase.
- Emits efficient template rendering avoiding redundant memory allocations as smartly as possible.
- HTML completions and hovers in
UI!by VSCode extension. ( search "uibeam" from extension marketplace )

Usage
[]
= "0.4"
When using uibeam just as a template engine, disabling client default feature is recommended
to eliminate useless dependencies:
[]
= { = "0.4", = false }
UI! syntax
use UI;
unsafely insert HTML string
raw string literal ( r#"..."# ) or unsafe block contents are rendered without HTML-escape :
use UI;
conditional & iterative rendering
{} at node-position in UI! can render, in addition to Display-able values, any impl IntoIterator<Item = UI>. This includes Option<UI> or any other iterators yielding UIs !
use ;
Beam - Component with Rust struct and JSX-like syntax
use ;
Client Component - WASM islands
overview
#[client] makes Beam a WASM island : initially rendered on server, sent with serialized props, and hydrated with deserialized props on browser.
Signal, computed, effect, batch, untracked are available in them.
note
Currently UIBeam's client component system is built upon Preact. This may be rewritten in pure Rust in the future, but may not because of potential reduction in the final .wasm size.
usage
working example: examples/counter
-
Activate
"client"feature, and addserdeto your dependencies:[] = { = "0.4" } = { = "1", = ["derive"] } -
Configure to export all your client components from a specific library crate. (e.g.
lib.rsentrypoint, or another member crate of a workspace)(There's no problem if including ordinary
Beams, not only client ones, in the lib crate.)Additionally, specify
crate-type = ["cdylib", "rlib"]for the crate:[] = ["cdylib", "rlib"] -
Define and use your client components:
/* islands/src/lib.rs */ use ; use ; use ; // Client component located at **island boundary** // must be `Serialize + for<'de> Deserialize<'de>`. (see NOTE below) ; // `#[client]` makes Beam a Wasm island. // `(island)` means this beam is **island boundary**./* server/src/main.rs */ use Counter; use UI; asyncNOTE: Client Beam at island boundary must be
Serialize + for<'de> Deserialize<'de>for the Wasm island architecture. In contrast,#[client]components without(island), e.g. havingchildren: UIoron_something: Box<dyn FnOnce(Event)>as props, can NOT implementSerializenorDeserializeand can only be used internally inUI!of another client component. Especially note that client components at island boundary can't havechildren. -
Compile the lib crate into Wasm by
wasm-pack buildwithRUSTFLAGS='--cfg hydrate'and--out-name hydrate --target web:# example when naming the lib crate `islands` RUSTFLAGS='--cfg hydrate'# in a hot-reloading loop, `--dev` flag is recommended: RUSTFLAGS='--cfg hydrate'NOTE: Both
hydratecfg (not feature!) andhydrateout-name are required here. This restriction may be relaxted in future versions. -
Make sure that your server responds with a complete HTML consist of one
<html></html>containing your page contents.Then, setup your server to serve the output directory (default:
pkg) at/.uibeamroute:/* axum example */ use Router; use ServeDir;(as a result, generated
{crate name}/pkg/hydrate.jsis served at/.uibeam/hydrate.jsroute, which is automatically loaded together with corresponding .wasm file in the hydration step on browser.)
Integrations with web frameworks
Enables UI to be returned directly as a HTML response.
Axum - by "axum" feature
= { = "0.8" }
= { = "0.4", = ["axum"] }
use ;
use UI;
async
async
Actix Web - by "actix-web" feature
= { = "4.12" }
= { = "0.4", = ["actix-web"] }
use ;
use UI;
async
async
Ohkami - by "ohkami" feature
- UIBeam v0.3 is compatible with Ohkami v0.24.
- Ohkami's
openapifeature is supported via UIBeam'sopenapifeature flag. - UIBeam itself is runtime-agnostic and available with any async runtimes supported by Ohkami.
[]
= { = "1.48", = ["full"] }
= { = "0.24", = ["rt_tokio"] }
= { = "0.4", = ["ohkami"] }
# when using ohkami's "openapi" feature,
# activate also uibeam's "openapi" feature.
use ;
use UI;
async
async
License
UIBeam is licensed under MIT LICENSE.