Create single interface to get exports from Instance.exports

This adds a method that takes generic arguments as well so that
NativeFunc<Args, Rets> can also be `got` even though it has generic
parameters
This commit is contained in:
Mark McCaskey
2020-10-28 13:32:27 -07:00
parent 82330018c2
commit 8b87526d9d
4 changed files with 152 additions and 43 deletions

View File

@@ -201,6 +201,17 @@ macro_rules! impl_native_traits {
}
}
impl<'a, $( $x, )* Rets> crate::exports::ExportableWithGenerics<'a, ($( $x ),*), Rets> for NativeFunc<( $( $x ),* ), Rets>
where
$( $x: FromToNativeWasmType, )*
Rets: WasmTypeList,
{
fn get_self_from_extern_with_generics(_extern: &crate::externals::Extern) -> Result<Self, crate::exports::ExportError> {
use crate::exports::Exportable;
crate::Function::get_self_from_extern(_extern)?.native().map_err(|_| crate::exports::ExportError::IncompatibleType)
}
}
};
}