Introduction

Sauron is a web framework written in rust, which can compile to webassembly to help you create robust websites and web apps.

This guide will:

  • Show you how to make interactive apps with Sauron web framework.

A Quick Example

1use sauron::html::text;
2use sauron::prelude::*;
3use sauron::{node, Cmd, Component, Node, Program};
4
5#[derive(Debug)]
6pub enum Msg {
7    Increment,
8    Decrement,
9}
10
11pub struct App {
12    count: i32,
13}
14
15impl App {
16    pub fn new() -> Self {
17        App { count: 0 }
18    }
19}
20
21impl Component<Msg> for App {
22    fn view(&self) -> Node<Msg> {
23        node! {
24            <main>
25                <input type="button"
26                    value="+"
27                    key=1
28                    on_click={|_| {
29                        Msg::Increment
30                    }}
31                />
32                <div>{text(self.count)}</div>
33                <input type="button"
34                    value="-"
35                    key=1
36                    on_click={|_| {
37                        Msg::Decrement
38                    }}
39                />
40            </main>
41        }
42    }
43
44    fn update(&mut self, msg: Msg) -> Cmd<Self, Msg> {
45        match msg {
46            Msg::Increment => self.count += 1,
47            Msg::Decrement => self.count -= 1,
48        }
49        Cmd::none()
50    }
51}
52
53#[wasm_bindgen(start)]
54pub fn main() {
55    console_log::init_with_level(log::Level::Trace).unwrap();
56    console_error_panic_hook::set_once();
57    Program::mount_to_body(App::new());
58}

Why sauron?

  • No runtime errors in practice
  • Reliable refactoring
  • Automatically enforced semantic versioning for all dependent crates.