0.1.0 • Published 6 years ago

wasm-nanoid v0.1.0

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

wasm-nanoid

Tutorial for your first wasm package.

docker run -v "$PWD":/usr/src/myapp -w /usr/src/myapp --rm --interactive --tty stereobooster/rust-wasm
USER=stereobooster cargo generate --git https://github.com/rustwasm/wasm-pack-template
cd wasm-nanoid

Use your github handle instead of mine (USER=stereobooster).

Edit Cargo.toml:

description = "nanoid implemented in wasm"
repository = "https://github.com/stereobooster/wasm-nanoid"
license = "MIT"

Edit README.md. Run:

wasm-pack init

Add to .gitignore:

*.log
pkg/*

Commit (you may want to do this in different terminal, because git inside Docker is not configured).

git add .
git commit -m "initial commit"

I want to build simple thing, so I will reuse existing Nano ID package (they call it crate in Rust).

Add dependency to Cargo.toml (this is like a package.json for npm):

nanoid = "0.2.0"

Edit src/lib.rs:

extern crate nanoid;

use wasm_bindgen::prelude::*;

#[wasm_bindgen]
pub fn simpleNanoid() -> JsValue {
    JsValue::from_str(&nanoid::simple())
}
0.1.0

6 years ago