rust-wasm-conventions
Installation
SKILL.md
Rust WebAssembly Conventions
Apply these conventions only when the project uses wasm-bindgen, wasm-pack, or targets wasm32-unknown-unknown. These rules are written for any coding agent, including Claude Code, Codex, Cursor, and Copilot.
Project Setup
- Use
wasm-packfor building, testing, and packaging. - Build with
wasm-pack build. - Set the crate type to
cdylibinCargo.toml:crate-type = ["cdylib"]. - Use
wasm-bindgenas the primary bridge between Rust and JavaScript.
#[wasm_bindgen]
- Annotate exported
pub struct,pub enum, andimplblocks with#[wasm_bindgen]. - Use
#[repr(u8)]on enums exposed to JavaScript when compact single-byte representation is useful. - Expose constructors as
pub fn new() -> Selfinside a#[wasm_bindgen]impl block. - Keep functions intended only for Rust-side tests in impl blocks without
#[wasm_bindgen].