51 lines
920 B
Rust
Raw Normal View History

extern crate wasm_bindgen;
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
2018-06-27 22:42:34 -07:00
extern "C" {
#[wasm_bindgen(js_namespace = console)]
fn log(s: &str);
}
#[wasm_bindgen]
2018-09-17 18:35:41 -07:00
#[derive(Debug)]
pub struct Counter {
key: char,
2018-06-27 22:42:34 -07:00
count: i32,
}
#[wasm_bindgen]
impl Counter {
pub fn default() -> Counter {
log("Counter::default");
Self::new('a', 0)
}
pub fn new(key: char, count: i32) -> Counter {
log(&format!("Counter::new({}, {})", key, count));
2018-06-27 22:42:34 -07:00
Counter {
key: key,
count: count,
}
}
pub fn key(&self) -> char {
log("Counter.key()");
self.key
}
pub fn count(&self) -> i32 {
log("Counter.count");
self.count
}
pub fn increment(&mut self) {
log("Counter.increment");
self.count += 1;
}
pub fn update_key(&mut self, key: char) {
self.key = key;
}
2018-06-27 22:42:34 -07:00
}