Skip to content

Instantly share code, notes, and snippets.

@mbalex99
Created May 18, 2018 01:36
Show Gist options
  • Save mbalex99/f7c948ad3231094d799a605b4b2f03ee to your computer and use it in GitHub Desktop.
Save mbalex99/f7c948ad3231094d799a605b4b2f03ee to your computer and use it in GitHub Desktop.
WASM Bindgen Simple Class
// A struct will show up as a class on the JS side of things
extern crate wasm_bindgen;
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
pub struct Bar {
contents: String,
}
#[wasm_bindgen]
impl Bar {
#[wasm_bindgen(constructor)]
pub fn new() -> Bar {
Bar {
contents: "Maximilian".to_string()
}
}
#[wasm_bindgen]
pub fn name(&self) -> String {
self.contents.clone()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment