1.9 KiB
1.9 KiB
Seed - Webfrontend in Rust
4 Webfrontend in Rust
Das Projekt
grid grid-cols-2 gap-8
fade-right
- 👨🏻💻 Entwickler: Martin Kavik
- ⚖️ MIT-Lizenz
- 📅 Erstes Release: 2019
Architektur
Code
Beispielprojekt: Zähler
Model (Zustand der Anwendung)
struct Model {
: i32,
counter}
fn init(_: Url, _: &mut impl Orders<Msg>) -> Model {
{ counter: 0 }
Model }
View (Stellt die Anwendung dar)
fn view(model: &Model) -> Node<Msg> {
div![
C!["counter"],
"This is a counter: ",
button![model.counter, ev(Ev::Click, |_| Msg::Increment),],
]}
Msg (Ändert den Zustand der Anwendung)
enum Msg {
,
Increment}
fn update(msg: Msg, model: &mut Model, _: &mut impl Orders<Msg>) {
match msg {
Msg::Increment => model.counter += 1,
}
}
Tooling
Trunk (Web application bundler für Rust)
Setup
fade-right
- Rust installieren (https://rustup.rs)
- WebAssembly-Target:
rustup target install wasm32-unknown-unknown
- Trunk installieren:
cargo install --locked trunk
- Anwendung mit
trunk serve
kompilieren und live im Browser anzeigen - Anwendung mit
trunk build --release
im Releasemodus kompilieren