Skip to content

Commit

Permalink
init. reproduces rust-random/rand#1016
Browse files Browse the repository at this point in the history
  • Loading branch information
kazcw committed Aug 19, 2020
0 parents commit e464734
Show file tree
Hide file tree
Showing 5 changed files with 234 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
/target
193 changes: 193 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions Cargo.toml
@@ -0,0 +1,12 @@
[package]
name = "rand1016"
version = "0.1.0"
authors = ["Kaz Wesley <kaz@lambdaverse.org>"]
edition = "2018"

[lib]
crate-type = ["cdylib"]

[dependencies]
wasm-bindgen = "0.2"
rand = "0.7"
17 changes: 17 additions & 0 deletions index.html
@@ -0,0 +1,17 @@
<html>
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type"/>
</head>
<body>
<!-- Note the usage of `type=module` here as this is an ES6 module -->
<script type="module">
import init, { test_rand1016 } from './pkg/rand1016.js';
async function run() {
await init();
const result = test_rand1016();
console.log(`result = ${result}`);
}
run();
</script>
</body>
</html>
11 changes: 11 additions & 0 deletions src/lib.rs
@@ -0,0 +1,11 @@
use rand::Rng;

use wasm_bindgen::prelude::*;

#[wasm_bindgen(start)]
pub fn main() -> Result<(), JsValue> { Ok(()) }

#[wasm_bindgen]
pub fn test_rand1016() -> u32 {
rand::thread_rng().gen()
}

0 comments on commit e464734

Please sign in to comment.