Reorganize the import_js example

This commit is contained in:
Alex Crichton
2019-03-25 13:49:05 -07:00
parent 362777fc75
commit faf49c7d56
7 changed files with 5 additions and 5 deletions

View File

@ -0,0 +1,35 @@
use wasm_bindgen::prelude::*;
#[wasm_bindgen(module = "/defined-in-js.js")]
extern "C" {
fn name() -> String;
type MyClass;
#[wasm_bindgen(constructor)]
fn new() -> MyClass;
#[wasm_bindgen(method, getter)]
fn number(this: &MyClass) -> u32;
#[wasm_bindgen(method, setter)]
fn set_number(this: &MyClass, number: u32) -> MyClass;
#[wasm_bindgen(method)]
fn render(this: &MyClass) -> String;
}
// lifted from the `console_log` example
#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(js_namespace = console)]
fn log(s: &str);
}
#[wasm_bindgen(start)]
pub fn run() {
log(&format!("Hello, {}!", name()));
let x = MyClass::new();
assert_eq!(x.number(), 42);
x.set_number(10);
log(&x.render());
}