Struct wasmedge_sdk::plugin::PluginModuleBuilder
source · pub struct PluginModuleBuilder<T: ?Sized + Send + Sync + Clone> { /* private fields */ }
Expand description
Implementations§
source§impl<T: ?Sized + Send + Sync + Clone> PluginModuleBuilder<T>
impl<T: ?Sized + Send + Sync + Clone> PluginModuleBuilder<T>
sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new PluginModuleBuilder.
sourcepub fn with_func<Args, Rets, D>(
self,
name: impl AsRef<str>,
real_func: impl Fn(CallingFrame, Vec<WasmValue>, *mut c_void) -> Result<Vec<WasmValue>, HostFuncError> + Send + Sync + 'static,
data: Option<Box<D>>
) -> WasmEdgeResult<Self>where
Args: WasmValTypeList,
Rets: WasmValTypeList,
pub fn with_func<Args, Rets, D>( self, name: impl AsRef<str>, real_func: impl Fn(CallingFrame, Vec<WasmValue>, *mut c_void) -> Result<Vec<WasmValue>, HostFuncError> + Send + Sync + 'static, data: Option<Box<D>> ) -> WasmEdgeResult<Self>where Args: WasmValTypeList, Rets: WasmValTypeList,
Adds a host function to the crate::ImportObject to create.
N.B. that this function can be used in thread-safe scenarios.
Arguments
-
name
- The exported name of the host function to add. -
real_func
- The native function. -
data
- The additional data object to set to this host function context.
error
If fail to create or add the host function, then an error is returned.
sourcepub fn with_async_func<Args, Rets, D>(
self,
name: impl AsRef<str>,
real_func: impl Fn(CallingFrame, Vec<WasmValue>, *mut c_void) -> Box<dyn Future<Output = Result<Vec<WasmValue>, HostFuncError>> + Send> + Send + Sync + 'static,
data: Option<Box<D>>
) -> WasmEdgeResult<Self>where
Args: WasmValTypeList,
Rets: WasmValTypeList,
D: Send + Sync,
Available on crate feature async
and Linux only.
pub fn with_async_func<Args, Rets, D>( self, name: impl AsRef<str>, real_func: impl Fn(CallingFrame, Vec<WasmValue>, *mut c_void) -> Box<dyn Future<Output = Result<Vec<WasmValue>, HostFuncError>> + Send> + Send + Sync + 'static, data: Option<Box<D>> ) -> WasmEdgeResult<Self>where Args: WasmValTypeList, Rets: WasmValTypeList, D: Send + Sync,
async
and Linux only.Adds an async host function to the PluginModule to create.
N.B. that this function can be used in thread-safe scenarios.
Arguments
-
name
- The exported name of the host function to add. -
real_func
- The native function.
error
If fail to create or add the host function, then an error is returned.
sourcepub fn with_global(self, name: impl AsRef<str>, global: Global) -> Self
pub fn with_global(self, name: impl AsRef<str>, global: Global) -> Self
Adds a global to the PluginModule to create.
Arguments
-
name
- The exported name of the global to add. -
global
- The wasm global instance to add.
sourcepub fn with_memory(self, name: impl AsRef<str>, memory: Memory) -> Self
pub fn with_memory(self, name: impl AsRef<str>, memory: Memory) -> Self
Adds a memory to the PluginModule to create.
Arguments
-
name
- The exported name of the memory to add. -
memory
- The wasm memory instance to add.
sourcepub fn with_table(self, name: impl AsRef<str>, table: Table) -> Self
pub fn with_table(self, name: impl AsRef<str>, table: Table) -> Self
Adds a table to the PluginModule to create.
Arguments
-
name
- The exported name of the table to add. -
table
- The wasm table instance to add.
sourcepub fn with_host_data(self, host_data: Box<T>) -> Self
pub fn with_host_data(self, host_data: Box<T>) -> Self
Adds host data to the PluginModule to create.
Arguments
-
host_data
- The host data to be stored in the module instance. -
finalizer
- The function to drop the host data. Notice that this argument is available only ifhost_data
is set some value.
sourcepub fn build(self, name: impl AsRef<str>) -> WasmEdgeResult<PluginModule>
pub fn build(self, name: impl AsRef<str>) -> WasmEdgeResult<PluginModule>
Creates a new PluginModule.
Argument
name
- The name of the PluginModule to create.
Error
If fail to create the PluginModule, then an error is returned.