Note: The contents of this repo are now significantly outdated. Check out rustwasm for the latest and greatest on how to integrate Rust ans WebAssembly.
Discussion on Hacker News.
This project demonstrates a complete, albeit simple, example of integrating Rust code into a web application. This is accomplished by compiling Rust to asm.js or WebAssembly. The basic design pattern this project explores uses Rust to implement CPU bound portions of an app while using existing web technologies to handle user facing, I/O bound pieces. The guide explores this design pattern in detail.
The project compares implementations of the k-means clustering algorithm (this example's CPU bound task) applied to an image. The algorithm gives the resulting image a softened, painted look.
See the guide for steps on installing the dependencies.
From the top level of the project run
cargo run
or
cargo run --release
The resulting painted image can be found at img/out.jpg.
From the top level of the project...
Build the asm.js version
cargo build --release --target asmjs-unknown-emscripten
Build the WebAssembly version
cargo build --release --target wasm32-unknown-emscripten
From the website/ directory...
Install node dependencies
npm install
Build the website (build results can be found in website/dist)
npm run build
or build the website in release mode
npm run build-release
or start a web server, website is served at http://localhost:9000/
npm run start