Alex Gourlay

WebAssembly iOS Calculator

Date

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).

WebAssembly iOS Calculator Screenshot
WebAssembly iOS Calculator Screenshot

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:

  1. ios_calculator - An implementation of the basic iOS calculator
  2. 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.

Get in touch

I'm always open to new ideas, new opportunities and new people. If you've got any of those things, then send a message over to me using the form below!

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.