Skip to content

Instantly share code, notes, and snippets.

@BruJu
Last active December 2, 2020 10:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BruJu/a135bab9e5ed553019f5666ed3343c02 to your computer and use it in GitHub Desktop.
Save BruJu/a135bab9e5ed553019f5666ed3343c02 to your computer and use it in GitHub Desktop.
wasmify-sophia : Add exported methods

https://github.com/BruJu/wasmify-sophia

wasm_bindgen_dataset!(TreedDataset, "TreedDataset", SophiaExportDataset);

+use crate::wrapping::*;
+
+#[wasm_bindgen(js_class="TreedDataset")]
+impl SophiaExportDataset {
+    pub fn get_nb_underlying(&self) -> usize {
+        self.base.dataset().get_number_of_underlying_trees()
+    }
+}

And that's it.

Explanation

  • The third argument is the name of the class that will be exported
  • Rust enables you to define multiple impl block
  • base is the adapter, base.dataset() is the Sophia compliant dataset
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment