🦀 Rust + 🕸 WebAssembly + ▲ Next.js = ❤️
This code shows how to import WebAssembly files (.wasm
) and use them inside a React (client-side) and Node (server-side) using Next.js. Here Rust is compiled to WebAssembly and wrapped in a npm package automatically generating package.json
, .wasm
, .js
and .d.ts
files.
You will need the standard Rust toolchain, including rustup
rustc
, and cargo
:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
Install also wasm-pack
:
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
Install other dependencies:
yarn install
Compile Rust code run:
yarn rust:dev
Run dev server:
yarn next:dev
The Richest Customer Wealth task with the same algorithm solution was used as a basic performance test.
You can compare performance using the following endpoints: /api/js/[number]
and /api/wasm/[number]
.