Fernando Bitti Loureiro aab99feb3e The example should output "Hello from Rust!" (#1931)
* Make console output "Hello from Rust!"

The HTML says the console would output Hello from Rust!, but instead it outputs Hello, World!
This is a proposed fix.

* Output "Hello from Rust!"

The HTML says the console would output "Hello from Rust!" but instead it outputs "Hello, World!".
This is a proposed fix.
2020-01-06 11:47:13 -06:00

36 lines
799 B
Rust

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 from {}!", name())); // should output "Hello from Rust!"
let x = MyClass::new();
assert_eq!(x.number(), 42);
x.set_number(10);
log(&x.render());
}