Sauron is a versatile web framework and library for building client-side and/or server-side web applications with strong focus on simplicity. It is suited for developing web application which uses progressive rendering.
In your src/lib.rs
```rust
use sauron::prelude::*;
enum Msg { Click, }
struct App { click_count: u32, }
impl App { pub fn new() -> Self { App { click_count: 0 } } }
impl Application"Minimal example"
fn update(&mut self, msg: Msg) -> Cmd<Self, Msg> {
log::trace!("App is updating with msg: {:?}", msg);
match msg {
Msg::Click => self.click_count += 1,
}
Cmd::none()
}
}
pub fn main() { consolelog::initwithlevel(log::Level::Trace).unwrap(); consoleerrorpanichook::setonce(); Program::mountto_body(App::new()); }
```
index.html
html
<html>
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type"/>
<title>Counter</title>
<style type="text/css">
body { font-family: verdana, arial, monospace; }
main {
width:30px;
height: 100px;
margin:auto;
text-align: center;
}
input, .count{
font-size: 40px;
padding: 30px;
}
</style>
<script type=module>
import init from './pkg/counter.js';
await init().catch(console.error);
</script>
</head>
<body>
</body>
</html>
In Cargo.toml
, specify the crate-type to be cdylib
```toml [package] name = "counter" version = "0.1.0" edition = "2018"
[lib] crate-type = ["cdylib"]
[dependencies] sauron = "0.49" ```
sh
cargo install wasm-pack
cargo install basic-http-server
Build using
sh
wasm-pack build --target web --release
Serve using
basic-http-server -a 0.0.0.0:4000
Then navigate to http://localhost:4000
For more details on the commands to build and serve, look on examples on this repo, each has scripts on how to build and run them.
License: MIT