-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Statically register host WASM functions #10394
Changes from 1 commit
a6b9624
1d8649f
2a4658f
878d512
7efc4f5
570788d
7610cde
0c51a64
963f9e7
76e8c96
e853225
df38788
3699f6d
cd14ed1
f825113
8ffb42d
0f7ccf8
e429bb9
9ce2fb7
f9019cd
acc2835
61ce0b2
bdd38da
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
rustfmt
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -362,8 +362,15 @@ if_wasmtime_is_enabled! { | |
| type State; | ||
| type Error; | ||
| type FunctionContext: FunctionContext; | ||
| fn with_function_context<R>(caller: wasmtime::Caller<Self::State>, callback: impl FnOnce(&mut dyn FunctionContext) -> R) -> R; | ||
| fn register_static<Params, Results>(&mut self, fn_name: &str, func: impl wasmtime::IntoFunc<Self::State, Params, Results> + 'static) -> core::result::Result<(), Self::Error>; | ||
| fn with_function_context<R>( | ||
| caller: wasmtime::Caller<Self::State>, | ||
| callback: impl FnOnce(&mut dyn FunctionContext) -> R, | ||
| ) -> R; | ||
| fn register_static<Params, Results>( | ||
| &mut self, | ||
| fn_name: &str, | ||
| func: impl wasmtime::IntoFunc<Self::State, Params, Results> + 'static, | ||
| ) -> core::result::Result<(), Self::Error>; | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -374,7 +381,9 @@ pub trait HostFunctions: 'static + Send + Sync { | |
|
|
||
| if_wasmtime_is_enabled! { | ||
| /// Statically registers the host functions. | ||
| fn register_static<T>(registry: &mut T) -> core::result::Result<(), T::Error> where T: HostFunctionRegistry; | ||
| fn register_static<T>(registry: &mut T) -> core::result::Result<(), T::Error> | ||
| where | ||
| T: HostFunctionRegistry; | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -423,22 +432,38 @@ where | |
| } | ||
|
|
||
| if_wasmtime_is_enabled! { | ||
| fn register_static<T>(registry: &mut T) -> core::result::Result<(), T::Error> where T: HostFunctionRegistry { | ||
| struct Proxy<'a, T> where T: HostFunctionRegistry { | ||
| fn register_static<T>(registry: &mut T) -> core::result::Result<(), T::Error> | ||
| where | ||
| T: HostFunctionRegistry, | ||
| { | ||
| struct Proxy<'a, T> | ||
| where | ||
| T: HostFunctionRegistry, | ||
| { | ||
| registry: &'a mut T, | ||
| seen: std::collections::HashSet<String> | ||
| seen: std::collections::HashSet<String>, | ||
| } | ||
| impl<'a, T> HostFunctionRegistry for Proxy<'a, T> where T: HostFunctionRegistry { | ||
| impl<'a, T> HostFunctionRegistry for Proxy<'a, T> | ||
| where | ||
| T: HostFunctionRegistry, | ||
| { | ||
| type State = T::State; | ||
| type Error = T::Error; | ||
| type FunctionContext = T::FunctionContext; | ||
| fn with_function_context<R>(caller: wasmtime::Caller<Self::State>, callback: impl FnOnce(&mut dyn FunctionContext) -> R) -> R { | ||
| fn with_function_context<R>( | ||
| caller: wasmtime::Caller<Self::State>, | ||
| callback: impl FnOnce(&mut dyn FunctionContext) -> R, | ||
| ) -> R { | ||
| T::with_function_context(caller, callback) | ||
| } | ||
|
|
||
| fn register_static<Params, Results>(&mut self, fn_name: &str, func: impl wasmtime::IntoFunc<Self::State, Params, Results> + 'static) -> core::result::Result<(), Self::Error> { | ||
| fn register_static<Params, Results>( | ||
| &mut self, | ||
| fn_name: &str, | ||
| func: impl wasmtime::IntoFunc<Self::State, Params, Results> + 'static, | ||
| ) -> core::result::Result<(), Self::Error> { | ||
| if self.seen.contains(fn_name) { | ||
|
||
| return Ok(()); | ||
| return Ok(()) | ||
| } | ||
|
|
||
| self.seen.insert(fn_name.to_owned()); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.