mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-13 04:51:23 +00:00
add char support (#206)
* add char support * add char test * remove __wbindgen_char fns * re-order travis script * update serve script * remove binds to unused char functions * add more wide character items to chars list * remove unused code * add char to readme * remove built file
This commit is contained in:
committed by
Alex Crichton
parent
17861a45ab
commit
4ddd93d75d
49
examples/char/src/lib.rs
Normal file
49
examples/char/src/lib.rs
Normal file
@ -0,0 +1,49 @@
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen]
|
||||
extern {
|
||||
#[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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user