Created
May 18, 2018 01:36
-
-
Save mbalex99/f7c948ad3231094d799a605b4b2f03ee to your computer and use it in GitHub Desktop.
WASM Bindgen Simple Class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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