About this project
The Rust WASM Calculator is a small open source project built by Peter Sjolin and published by Pigfox LLC. It exists to show that a browser tool can put its correctness-critical logic in a compiled, tested language without asking the user to install anything or to send their data to a server. The whole thing is a static page, a stylesheet, one JavaScript file, and one WebAssembly module.
How it is built
The arithmetic engine is a Rust crate using the 2021 edition. It builds as both a native Rust library and a WebAssembly module, which is why its 86 unit tests can run without a browser. The bridge to JavaScript is provided by wasm-bindgen, with serde and serde-wasm-bindgen handling the conversion of the calculation history into a plain JavaScript object.
- Engine: a single Rust source file compiled to WebAssembly.
- Build:
wasm-pack build --target web, producing an ES module. - Front end: one HTML page, one stylesheet, one JavaScript module. No framework.
- Tests: 86 native Rust unit tests plus 11 tests run against the compiled WebAssembly.
- Licence: MIT.
Each of those has a page of its own: what the build emits, how the tests are split, how to build it yourself, and how values cross the boundary.
Why it exists
Most calculators on the web are a few lines of JavaScript, and most of them are wrong in the same three places: dividing by zero gives Infinity, the square root of a negative number gives NaN, and a large factorial silently wraps around to a small number. None of those produces an error message; they produce a number that looks like an answer. This project is a demonstration that moving the arithmetic into a compiled language with a real error type removes that whole category of failure at the cost of a single build step.
It is also a working example of the wasm-bindgen toolchain end to end: a Rust crate that is simultaneously a native library you can unit test and a WebAssembly module a browser can import as an ES module, with typed errors crossing the boundary as JavaScript exceptions and a serialisable history struct crossing it as a plain object. Nothing here is a framework: the calculator is one HTML page, two stylesheets and one script, and the reference pages around it are plain static HTML generated at build time from a small Go program in this repository.
Privacy and hosting
The calculator has no backend and no calculation API, so there is nothing for it to send and nothing for anyone to collect. Every key press is a local function call inside the page. The site does load Google Analytics for aggregate page view counts, which is the only third-party request the page makes; it is not tied to anything you type into the calculator, because what you type never leaves the WebAssembly module.
Source code
The repository is public at github.com/pigfox/rust-wasm-calc. Everything described anywhere on this site can be checked against it: the operations, the error messages, the factorial limit, and the test count. It is released under the MIT licence.
Questions and answers
Who publishes the Rust WASM Calculator?
It is published by Pigfox LLC and was built by Peter Sjolin.
Is the source code available?
Yes. The full source is public at github.com/pigfox/rust-wasm-calc under the MIT licence, including the Rust engine, the page JavaScript, the static page generator, and the build script.