impl_wasm_map_insert_get

Macro impl_wasm_map_insert_get 

Source
macro_rules! impl_wasm_map_insert_get {
    ($rust_key:ty, $wasm_key:ty, $wasm_value:ty, $wasm_map_name:ident, false, false, $key_copy:tt, $val_copy:tt) => { ... };
    ($rust_key:ty, $wasm_key:ty, $wasm_value:ty, $wasm_map_name:ident, false, true, $key_copy:tt, $val_copy:tt) => { ... };
    ($rust_key:ty, $wasm_key:ty, $wasm_value:ty, $wasm_map_name:ident, true, false, $key_copy:tt, $val_copy:tt) => { ... };
    ($rust_key:ty, $wasm_key:ty, $wasm_value:ty, $wasm_map_name:ident, true, true, $key_copy:tt, $val_copy:tt) => { ... };
}
Expand description

This shouldn’t be explicitly called - only via impl_wasm_map!() We use this to get around restrictions in outer macros evaluating before inner macros which breaks wasm_bindgen’s parameter parsing resulting in FromWasmAbi on &T instead of RefFromWasmAbi on T being used. This happened when these were inlined directly in impl_wasm_map!() e.g.:

#[macro_export] macro_rules! wasm_type_param { ($wasm_type:ty, true) => { $wasm_type }; ($wasm_type:ty, false) => { &$wasm_type }; }

Then used within the impl of the wasm_bindgen map:

pub fn get(&self, key: $crate::wasm_type_param!($wasm_key, $key_wasm_abi)) -> Option<$wasm_value> { $crate::wasm_option_return!( self.0.get(key.as_ref()), $val_wasm_abi) } pub fn insert( &mut self, key: $crate::wasm_type_param!($wasm_key, $key_wasm_abi), value: $crate::wasm_type_param!($wasm_value, $val_wasm_abi) ) -> Option<$wasm_value> { self.0.insert( $crate::wasm_val_clone!(key, $key_wasm_abi), $crate::wasm_val_clone!(value, $val_wasm_abi)) }