Last active
December 15, 2018 07:51
-
-
Save dorayakikun/5a82c8c224466477ce9372c9e39562d1 to your computer and use it in GitHub Desktop.
Rust入門者向けハンズオン #5向け向け
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const js = import("./rust_handson"); | |
js.then(js => { | |
js.to_hash("World!"); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate wasm_bindgen; | |
use wasm_bindgen::prelude::*; | |
use std::collections::hash_map::DefaultHasher; | |
use std::hash::{Hash, Hasher}; | |
#[wasm_bindgen] | |
extern "C" { | |
fn alert(s: &str); | |
} | |
#[wasm_bindgen] | |
pub fn to_hash(s: &str) { | |
let mut hasher = DefaultHasher::new(); | |
s.as_bytes().hash(&mut hasher); | |
alert(&format!("{:x}", hasher.finish())); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment