First working version
This commit is contained in:
45
src/lib.rs
Normal file
45
src/lib.rs
Normal file
@@ -0,0 +1,45 @@
|
||||
mod obsidian;
|
||||
use js_sys::JsString;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub struct ExampleCommand {
|
||||
id: JsString,
|
||||
name: JsString,
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
impl ExampleCommand {
|
||||
#[wasm_bindgen(getter)]
|
||||
pub fn id(&self) -> JsString {
|
||||
self.id.clone()
|
||||
}
|
||||
|
||||
#[wasm_bindgen(setter)]
|
||||
pub fn set_id(&mut self, id: &str) {
|
||||
self.id = JsString::from(id)
|
||||
}
|
||||
|
||||
#[wasm_bindgen(getter)]
|
||||
pub fn name(&self) -> JsString {
|
||||
self.name.clone()
|
||||
}
|
||||
|
||||
#[wasm_bindgen(setter)]
|
||||
pub fn set_name(&mut self, name: &str) {
|
||||
self.name = JsString::from(name)
|
||||
}
|
||||
|
||||
pub fn callback(&self) {
|
||||
obsidian::Notice::new("hello from rust");
|
||||
}
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn onload(plugin: &obsidian::Plugin) {
|
||||
let cmd = ExampleCommand {
|
||||
id: JsString::from("example"),
|
||||
name: JsString::from("Example"),
|
||||
};
|
||||
plugin.addCommand(JsValue::from(cmd))
|
||||
}
|
||||
14
src/obsidian.rs
Normal file
14
src/obsidian.rs
Normal file
@@ -0,0 +1,14 @@
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen(module = "obsidian")]
|
||||
extern "C" {
|
||||
pub type Plugin;
|
||||
|
||||
#[wasm_bindgen(structural, method)]
|
||||
pub fn addCommand(this: &Plugin, command: JsValue);
|
||||
|
||||
pub type Notice;
|
||||
|
||||
#[wasm_bindgen(constructor)]
|
||||
pub fn new(message: &str) -> Notice;
|
||||
}
|
||||
Reference in New Issue
Block a user