Seed Component with Click Counter - Seed-rust Typing CST Test
Loading…
Seed Component with Click Counter — Seed-rust Code
Counts clicks on a button and displays the count.
# seed/demo/click_counter.rs
use seed::{prelude::*, *};
struct Model { count: i32 }
enum Msg { Click }
fn init(_: Url, _: &mut Orders<Msg>) -> Model {
Model { count: 0 }
}
fn update(msg: Msg, model: &mut Model, _: &mut Orders<Msg>) {
if let Msg::Click = msg {
model.count += 1
}
}
fn view(model: &Model) -> Node<Msg> {
div![
button![ev(Ev::Click, |_| Msg::Click), "Click me"],
span![model.count]
]
}
#[wasm_bindgen(start)]
pub fn start() {
App::start("app", init, update, view);
}Seed-rust Language Guide
Seed is a Rust framework for creating front-end web apps with WebAssembly. It provides a component-based architecture inspired by Elm, enabling Rust developers to write type-safe, reactive web applications that compile to Wasm.
Primary Use Cases
- ▸Single-page web applications (SPAs) in Rust
- ▸High-performance dashboards and visualizations
- ▸Interactive web games
- ▸Wasm modules for web apps with Rust logic
- ▸Integration-heavy front-end apps needing Rust crates
Notable Features
- ▸Component-based architecture similar to Elm
- ▸Virtual DOM for efficient UI updates
- ▸Reactive message-driven state management
- ▸Rust-to-Wasm compilation for high performance
- ▸Works with wasm-bindgen to access JS and Web APIs
Origin & Creator
Seed was created by IcedDev and the Rust community, first appearing around 2018.
Industrial Note
Seed-Rust is ideal for developers who want Rust’s safety and performance for front-end web apps, especially for Wasm-based projects where speed and correctness are critical.