Skip to content

Instantly share code, notes, and snippets.

@dorayakikun
Last active December 15, 2018 07:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dorayakikun/5a82c8c224466477ce9372c9e39562d1 to your computer and use it in GitHub Desktop.
Save dorayakikun/5a82c8c224466477ce9372c9e39562d1 to your computer and use it in GitHub Desktop.
Rust入門者向けハンズオン #5向け向け
const js = import("./rust_handson");
js.then(js => {
js.to_hash("World!");
});
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