WebAssembly iOS Calculator
Date
Link
Website
Organisation
Personal
Role
Software development
Repository
wasm-ios-calc
Technologies
Rust|Vite|wasm-bindgen|WebAssembly
Overview
I worked on this project with the aim of strengthening my understanding of the Rust programming language and its ability to compile into WebAssembly using wasm-pack. I had been reading through the excellent Rust Book for some time and wanted to apply my knowledge. The best way of learning is by doing!
I decided to clone an existing application as this allowed me to focus just on the implementation, rather than spending time thinking about the functionality and appearance. The iOS calculator, or any standard calculator, involves a fairly low level of complexity which makes it an ideal option for recreating. I'm sure there have been many iOS calculator clones created in the past, however this is the first to be made using Rust & WebAssembly (I think).
The UI and input handling was delegated to Javascript, whereby the creation of the calulcator buttons was done programatically using a createKeypadButtons
function. This could have all been done within Rust using the web-sys crate, which exposes all the Web APIs, however I wanted to use Rust to focus only on the logic and state of the calculator instead.
When structuring the Rust code, I created a workspace that contained 2 crates:
- ios_calculator - An implementation of the basic iOS calculator
- wasm_ios_calculator - A wrapper for ios_calculator that compiles to WebAssembly and uses wasm_bindgen to expose its methods.
This way I could separate out the calculator code from the WASM specific code. The ios_calculator crate was then made publicly available by publishing to crates.io.