mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-04-15 08:56:04 +00:00
53 lines
952 B
Rust
53 lines
952 B
Rust
#![feature(use_extern_macros)]
|
|
|
|
extern crate wasm_bindgen;
|
|
|
|
use wasm_bindgen::prelude::*;
|
|
|
|
#[wasm_bindgen]
|
|
extern "C" {
|
|
#[wasm_bindgen(js_namespace = console)]
|
|
fn log(s: &str);
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
#[wasm_bindgen]
|
|
pub struct Counter {
|
|
key: char,
|
|
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));
|
|
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;
|
|
}
|
|
}
|