1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
use wasm_bindgen::prelude::*;

#[macro_export]
macro_rules! bind {
    ($namespace:ident, $target:ident) => {
        #[wasm_bindgen]
        extern "C" {
            type $namespace;

            #[wasm_bindgen(catch, js_name = "delete", static_method_of = $namespace)]
            async fn delete(key: JsValue) -> Result<(), JsValue>;
        }

        struct $target;

        impl $target {
            pub async fn delete(key: &str) -> Result<(), JsValue> {
                // Convert the key into a JS value:
                let key = JsValue::from_str(key);
                // Call the imported delete JS method:
                $namespace::delete(key).await
            }
        }
    };
}