| 1 | # wasm |
| 2 | |
| 3 | A Durable Object counter in Rust, compiled to Wasm with |
| 4 | [workers-rs](https://github.com/cloudflare/workers-rs). |
| 5 | |
| 6 | `worker-build` is the workers-rs build tool. It compiles the crate to |
| 7 | `wasm32-unknown-unknown`, runs wasm-bindgen over the output, and |
| 8 | writes the JavaScript entry point (`build/worker/shim.mjs`) that |
| 9 | `wrangler.jsonc` names as `main` — you do not write any JavaScript |
| 10 | yourself. Install it once, build, and deploy: |
| 11 | |
| 12 | ```sh |
| 13 | rustup target add wasm32-unknown-unknown |
| 14 | cargo install worker-build |
| 15 | |
| 16 | worker-build --release |
| 17 | celld deploy . --bucket s3://my-cells-bucket |
| 18 | ``` |
| 19 | |
| 20 | ```sh |
| 21 | curl http://localhost:8080/c/hello # {"lang":"rust","n":1,"name":"hello"} |
| 22 | curl http://localhost:8080/c/hello # n increments — state lives in the cell |
| 23 | curl http://localhost:8080/c/other # a different cell, its own counter |
| 24 | ``` |
| 25 | |
| 26 | See [the WebAssembly docs](../../docs/wasm.md) for how celld ships and |
| 27 | runs the `.wasm` module. Contributed by |
| 28 | [Connor Hindley](https://github.com/connyay). |