2018-05-23 12:06:49 -07:00
|
|
|
use wasm_bindgen::prelude::*;
|
|
|
|
|
2019-02-27 09:45:34 -08:00
|
|
|
#[wasm_bindgen(module = "/defined-in-js.js")]
|
2018-06-27 22:42:34 -07:00
|
|
|
extern "C" {
|
2018-05-23 12:06:49 -07:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-09-20 16:20:42 -07:00
|
|
|
// lifted from the `console_log` example
|
2018-05-23 12:06:49 -07:00
|
|
|
#[wasm_bindgen]
|
2018-06-27 22:42:34 -07:00
|
|
|
extern "C" {
|
2018-05-23 12:06:49 -07:00
|
|
|
#[wasm_bindgen(js_namespace = console)]
|
|
|
|
fn log(s: &str);
|
|
|
|
}
|
|
|
|
|
2018-11-28 09:25:51 -08:00
|
|
|
#[wasm_bindgen(start)]
|
2018-05-23 12:06:49 -07:00
|
|
|
pub fn run() {
|
|
|
|
log(&format!("Hello, {}!", name()));
|
|
|
|
|
|
|
|
let x = MyClass::new();
|
|
|
|
assert_eq!(x.number(), 42);
|
|
|
|
x.set_number(10);
|
|
|
|
log(&x.render());
|
|
|
|
}
|