diff --git a/crates/wasmedge-sys/src/async/module.rs b/crates/wasmedge-sys/src/async/module.rs index 8760d7111..eea13bc67 100644 --- a/crates/wasmedge-sys/src/async/module.rs +++ b/crates/wasmedge-sys/src/async/module.rs @@ -2341,7 +2341,7 @@ impl async_wasi::snapshots::common::memory::Memory for Memory { mod tests { use super::*; use crate::{ - r#async::fiber::AsyncState, Config, Executor, ImportObject, Loader, Store, Validator, + r#async::fiber::AsyncState, Config, Executor, Loader, Store, Validator, WasiInstance, }; #[tokio::test] @@ -2368,8 +2368,8 @@ mod tests { let async_wasi_module = result.unwrap(); // register async_wasi module into the store - let wasi_import = ImportObject::AsyncWasi(async_wasi_module); - let result = executor.register_import_object(&mut store, &wasi_import); + let wasi_import = WasiInstance::AsyncWasi(async_wasi_module); + let result = executor.register_wasi_instance(&mut store, &wasi_import); assert!(result.is_ok()); let wasm_file = std::env::current_dir() diff --git a/crates/wasmedge-sys/src/executor.rs b/crates/wasmedge-sys/src/executor.rs index 3ff2f80b5..8c4074089 100644 --- a/crates/wasmedge-sys/src/executor.rs +++ b/crates/wasmedge-sys/src/executor.rs @@ -5,7 +5,7 @@ use super::ffi; use crate::r#async::fiber::{AsyncState, FiberFuture}; use crate::{ instance::module::InnerInstance, types::WasmEdgeString, utils::check, Config, Engine, FuncRef, - Function, ImportModule, ImportObject, Instance, Module, Statistics, Store, WasmEdgeResult, + Function, ImportModule, Instance, Module, Statistics, Store, WasiInstance, WasmEdgeResult, WasmValue, }; use parking_lot::Mutex; @@ -57,25 +57,25 @@ impl Executor { } } - /// Registers and instantiates a WasmEdge [import object](crate::ImportObject) into a [store](crate::Store). + /// Registers and instantiates the given [WASI instance](crate::WasiInstance) into a [store](crate::Store). /// /// # Arguments /// /// * `store` - The target [store](crate::Store), into which the given [import object](crate::ImportObject) is registered. /// - /// * `import` - The WasmEdge [import object](crate::ImportObject) to be registered. + /// * `instance` - The [WASI instance](crate::WasiInstance) to be registered. /// /// # Error /// - /// If fail to register the given [import object](crate::ImportObject), then an error is returned. - pub fn register_import_object( + /// If fail to register the given [WASI instance](crate::WasiInstance), then an error is returned. + pub fn register_wasi_instance( &mut self, store: &Store, - import: &ImportObject, + instance: &WasiInstance, ) -> WasmEdgeResult<()> { - match import { + match instance { #[cfg(not(feature = "async"))] - ImportObject::Wasi(import) => unsafe { + WasiInstance::Wasi(import) => unsafe { check(ffi::WasmEdge_ExecutorRegisterImport( self.inner.0, store.inner.0, @@ -83,7 +83,7 @@ impl Executor { ))?; }, #[cfg(all(feature = "async", target_os = "linux"))] - ImportObject::AsyncWasi(import) => unsafe { + WasiInstance::AsyncWasi(import) => unsafe { check(ffi::WasmEdge_ExecutorRegisterImport( self.inner.0, store.inner.0, @@ -625,8 +625,8 @@ mod tests { assert!(result.is_ok()); let async_wasi_module = result.unwrap(); - let wasi_import = ImportObject::AsyncWasi(async_wasi_module); - let result = executor.register_import_object(&mut store, &wasi_import); + let wasi_import = WasiInstance::AsyncWasi(async_wasi_module); + let result = executor.register_wasi_instance(&mut store, &wasi_import); assert!(result.is_ok()); // register async_wasi module into the store @@ -706,8 +706,8 @@ mod tests { let async_wasi_module = result.unwrap(); // register async_wasi module into the store - let wasi_import = ImportObject::AsyncWasi(async_wasi_module); - let result = executor.register_import_object(&mut store, &wasi_import); + let wasi_import = WasiInstance::AsyncWasi(async_wasi_module); + let result = executor.register_wasi_instance(&mut store, &wasi_import); assert!(result.is_ok()); let ty = FuncType::create([], [])?; diff --git a/crates/wasmedge-sys/src/instance/module.rs b/crates/wasmedge-sys/src/instance/module.rs index e12277a75..fa6f935ba 100644 --- a/crates/wasmedge-sys/src/instance/module.rs +++ b/crates/wasmedge-sys/src/instance/module.rs @@ -608,6 +608,11 @@ impl WasiModule { } } + /// Returns the name of the module instance. + pub fn name(&self) -> &str { + "wasi_snapshot_preview1" + } + /// Initializes the WASI host module with the given parameters. /// /// # Arguments @@ -712,251 +717,6 @@ impl WasiModule { self.inner.0 as *const _ } } -#[cfg(not(feature = "async"))] -impl AsInstance for WasiModule { - fn get_func(&self, name: impl AsRef) -> WasmEdgeResult { - let func_name: WasmEdgeString = name.as_ref().into(); - let func_ctx = unsafe { - ffi::WasmEdge_ModuleInstanceFindFunction(self.inner.0 as *const _, func_name.as_raw()) - }; - match func_ctx.is_null() { - true => Err(Box::new(WasmEdgeError::Instance( - InstanceError::NotFoundFunc(name.as_ref().to_string()), - ))), - false => Ok(Function { - inner: Arc::new(Mutex::new(InnerFunc(func_ctx))), - registered: true, - }), - } - } - - fn get_table(&self, name: impl AsRef) -> WasmEdgeResult { - let table_name: WasmEdgeString = name.as_ref().into(); - let ctx = unsafe { - ffi::WasmEdge_ModuleInstanceFindTable(self.inner.0 as *const _, table_name.as_raw()) - }; - match ctx.is_null() { - true => Err(Box::new(WasmEdgeError::Instance( - InstanceError::NotFoundTable(name.as_ref().to_string()), - ))), - false => Ok(Table { - inner: Arc::new(Mutex::new(InnerTable(ctx))), - registered: true, - }), - } - } - - fn get_memory(&self, name: impl AsRef) -> WasmEdgeResult { - let mem_name: WasmEdgeString = name.as_ref().into(); - let ctx = unsafe { - ffi::WasmEdge_ModuleInstanceFindMemory(self.inner.0 as *const _, mem_name.as_raw()) - }; - match ctx.is_null() { - true => Err(Box::new(WasmEdgeError::Instance( - InstanceError::NotFoundMem(name.as_ref().to_string()), - ))), - false => Ok(Memory { - inner: Arc::new(Mutex::new(InnerMemory(ctx))), - registered: true, - }), - } - } - - fn get_global(&self, name: impl AsRef) -> WasmEdgeResult { - let global_name: WasmEdgeString = name.as_ref().into(); - let ctx = unsafe { - ffi::WasmEdge_ModuleInstanceFindGlobal(self.inner.0 as *const _, global_name.as_raw()) - }; - match ctx.is_null() { - true => Err(Box::new(WasmEdgeError::Instance( - InstanceError::NotFoundGlobal(name.as_ref().to_string()), - ))), - false => Ok(Global { - inner: Arc::new(Mutex::new(InnerGlobal(ctx))), - registered: true, - }), - } - } - - /// Returns the length of the exported [function instances](crate::Function) in this module instance. - fn func_len(&self) -> u32 { - unsafe { ffi::WasmEdge_ModuleInstanceListFunctionLength(self.inner.0) } - } - - /// Returns the names of the exported [function instances](crate::Function) in this module instance. - fn func_names(&self) -> Option> { - let len_func_names = self.func_len(); - match len_func_names > 0 { - true => { - let mut func_names = Vec::with_capacity(len_func_names as usize); - unsafe { - ffi::WasmEdge_ModuleInstanceListFunction( - self.inner.0, - func_names.as_mut_ptr(), - len_func_names, - ); - func_names.set_len(len_func_names as usize); - } - - let names = func_names - .into_iter() - .map(|x| x.into()) - .collect::>(); - Some(names) - } - false => None, - } - } - - /// Returns the length of the exported [table instances](crate::Table) in this module instance. - fn table_len(&self) -> u32 { - unsafe { ffi::WasmEdge_ModuleInstanceListTableLength(self.inner.0) } - } - - /// Returns the names of the exported [table instances](crate::Table) in this module instance. - fn table_names(&self) -> Option> { - let len_table_names = self.table_len(); - match len_table_names > 0 { - true => { - let mut table_names = Vec::with_capacity(len_table_names as usize); - unsafe { - ffi::WasmEdge_ModuleInstanceListTable( - self.inner.0, - table_names.as_mut_ptr(), - len_table_names, - ); - table_names.set_len(len_table_names as usize); - } - - let names = table_names - .into_iter() - .map(|x| x.into()) - .collect::>(); - Some(names) - } - false => None, - } - } - - /// Returns the length of the exported [memory instances](crate::Memory) in this module instance. - fn mem_len(&self) -> u32 { - unsafe { ffi::WasmEdge_ModuleInstanceListMemoryLength(self.inner.0) } - } - - /// Returns the names of all exported [memory instances](crate::Memory) in this module instance. - fn mem_names(&self) -> Option> { - let len_mem_names = self.mem_len(); - match len_mem_names > 0 { - true => { - let mut mem_names = Vec::with_capacity(len_mem_names as usize); - unsafe { - ffi::WasmEdge_ModuleInstanceListMemory( - self.inner.0, - mem_names.as_mut_ptr(), - len_mem_names, - ); - mem_names.set_len(len_mem_names as usize); - } - - let names = mem_names - .into_iter() - .map(|x| x.into()) - .collect::>(); - Some(names) - } - false => None, - } - } - - /// Returns the length of the exported [global instances](crate::Global) in this module instance. - fn global_len(&self) -> u32 { - unsafe { ffi::WasmEdge_ModuleInstanceListGlobalLength(self.inner.0) } - } - - /// Returns the names of the exported [global instances](crate::Global) in this module instance. - fn global_names(&self) -> Option> { - let len_global_names = self.global_len(); - match len_global_names > 0 { - true => { - let mut global_names = Vec::with_capacity(len_global_names as usize); - unsafe { - ffi::WasmEdge_ModuleInstanceListGlobal( - self.inner.0, - global_names.as_mut_ptr(), - len_global_names, - ); - global_names.set_len(len_global_names as usize); - } - - let names = global_names - .into_iter() - .map(|x| x.into()) - .collect::>(); - Some(names) - } - false => None, - } - } -} -#[cfg(not(feature = "async"))] -impl AsImport for WasiModule { - fn name(&self) -> &str { - "wasi_snapshot_preview1" - } - - fn add_func(&mut self, name: impl AsRef, func: Function) { - self.funcs.push(func); - let f = self.funcs.last_mut().unwrap(); - - let func_name: WasmEdgeString = name.into(); - unsafe { - ffi::WasmEdge_ModuleInstanceAddFunction( - self.inner.0, - func_name.as_raw(), - f.inner.lock().0, - ); - } - } - - fn add_table(&mut self, name: impl AsRef, table: Table) { - let table_name: WasmEdgeString = name.as_ref().into(); - unsafe { - ffi::WasmEdge_ModuleInstanceAddTable( - self.inner.0, - table_name.as_raw(), - table.inner.lock().0, - ); - } - - table.inner.lock().0 = std::ptr::null_mut(); - } - - fn add_memory(&mut self, name: impl AsRef, memory: Memory) { - let mem_name: WasmEdgeString = name.as_ref().into(); - unsafe { - ffi::WasmEdge_ModuleInstanceAddMemory( - self.inner.0, - mem_name.as_raw(), - memory.inner.lock().0, - ); - } - - memory.inner.lock().0 = std::ptr::null_mut(); - } - - fn add_global(&mut self, name: impl AsRef, global: Global) { - let global_name: WasmEdgeString = name.as_ref().into(); - unsafe { - ffi::WasmEdge_ModuleInstanceAddGlobal( - self.inner.0, - global_name.as_raw(), - global.inner.lock().0, - ); - } - - global.inner.lock().0 = std::ptr::null_mut(); - } -} /// The object to be registered via the the [Executor::register_import_object](crate::Executor::register_import_object) function is required to implement this trait. pub trait AsImport { @@ -1002,7 +762,7 @@ pub trait AsImport { /// Defines three types of module instances that can be imported into a WasmEdge [Store](crate::Store) instance. #[derive(Debug, Clone)] -pub enum ImportObject { +pub enum WasiInstance { /// Defines the import module instance of WasiModule type. #[cfg(not(feature = "async"))] Wasi(WasiModule), @@ -1010,14 +770,14 @@ pub enum ImportObject { #[cfg(all(feature = "async", target_os = "linux"))] AsyncWasi(AsyncWasiModule), } -impl ImportObject { +impl WasiInstance { /// Returns the name of the import object. pub fn name(&self) -> &str { match self { #[cfg(not(feature = "async"))] - ImportObject::Wasi(wasi) => wasi.name(), + WasiInstance::Wasi(wasi) => wasi.name(), #[cfg(all(feature = "async", target_os = "linux"))] - ImportObject::AsyncWasi(async_wasi) => async_wasi.name(), + WasiInstance::AsyncWasi(async_wasi) => async_wasi.name(), } } @@ -1026,9 +786,9 @@ impl ImportObject { pub fn as_raw_ptr(&self) -> *const ffi::WasmEdge_ModuleInstanceContext { match self { #[cfg(not(feature = "async"))] - ImportObject::Wasi(wasi) => wasi.inner.0, + WasiInstance::Wasi(wasi) => wasi.inner.0, #[cfg(all(feature = "async", target_os = "linux"))] - ImportObject::AsyncWasi(async_wasi) => async_wasi.inner.0, + WasiInstance::AsyncWasi(async_wasi) => async_wasi.inner.0, } } } diff --git a/crates/wasmedge-sys/src/lib.rs b/crates/wasmedge-sys/src/lib.rs index 5ff921728..8844f4aec 100644 --- a/crates/wasmedge-sys/src/lib.rs +++ b/crates/wasmedge-sys/src/lib.rs @@ -103,7 +103,7 @@ pub use instance::{ function::{FuncRef, FuncType, Function}, global::{Global, GlobalType}, memory::{MemType, Memory}, - module::{AsImport, AsInstance, ImportModule, ImportObject, Instance}, + module::{AsImport, AsInstance, ImportModule, Instance, WasiInstance}, table::{Table, TableType}, }; #[doc(inline)] diff --git a/crates/wasmedge-sys/src/plugin.rs b/crates/wasmedge-sys/src/plugin.rs index 7a4a47933..0a2456bcd 100644 --- a/crates/wasmedge-sys/src/plugin.rs +++ b/crates/wasmedge-sys/src/plugin.rs @@ -461,14 +461,13 @@ impl PluginDescriptor { /// Represents a Plugin module instance. #[derive(Debug, Clone)] -pub struct PluginModule { +pub struct PluginModule { pub(crate) inner: Arc, pub(crate) registered: bool, name: String, - _host_data: Option>, funcs: Vec, } -impl Drop for PluginModule { +impl Drop for PluginModule { fn drop(&mut self) { if !self.registered && Arc::strong_count(&self.inner) == 1 && !self.inner.0.is_null() { unsafe { @@ -480,28 +479,31 @@ impl Drop for PluginModule { } } } -impl PluginModule { +impl PluginModule { /// Creates a module instance which is used to import host functions, tables, memories, and globals into a wasm module. /// /// # Argument /// /// * `name` - The name of the import module instance. /// - /// * `host_data` - The host data to be stored in the module instance. + /// * `host_data` - The host context data to be used in the module instance. /// /// * `finalizer` - the function to drop the host data. This argument is only available when `host_data` is set. /// /// # Error /// /// If fail to create the import module instance, then an error is returned. - pub fn create(name: impl AsRef, mut host_data: Option>) -> WasmEdgeResult { + pub fn create(name: impl AsRef, host_data: Option>) -> WasmEdgeResult + where + T: ?Sized + Send + Sync + Clone, + { let raw_name = WasmEdgeString::from(name.as_ref()); - let ctx = match host_data.as_mut() { + let ctx = match host_data { Some(data) => unsafe { ffi::WasmEdge_ModuleInstanceCreateWithData( raw_name.as_raw(), - data.as_mut() as *mut T as *mut c_void, + Box::into_raw(data) as *mut c_void, Some(host_data_finalizer::), ) }, @@ -516,7 +518,6 @@ impl PluginModule { inner: std::sync::Arc::new(InnerInstance(ctx)), registered: false, name: name.as_ref().to_string(), - _host_data: host_data, funcs: Vec::new(), }), } @@ -528,7 +529,7 @@ impl PluginModule { self.inner.0 as *const _ } } -impl AsImport for PluginModule { +impl AsImport for PluginModule { fn name(&self) -> &str { self.name.as_str() } diff --git a/src/lib.rs b/src/lib.rs index d09cb901d..dde0d21c6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -86,6 +86,7 @@ pub mod types; pub mod utils; #[doc(hidden)] pub mod vm; +#[cfg(not(feature = "async"))] pub mod wasi; pub use caller::Caller; diff --git a/src/plugin.rs b/src/plugin.rs index 1ee5bc550..dda5fc1da 100644 --- a/src/plugin.rs +++ b/src/plugin.rs @@ -222,14 +222,14 @@ impl PluginVersion { /// [Create a simple math plugin](https://github.com/second-state/wasmedge-rustsdk-examples/tree/main/simple-plugin) /// #[derive(Debug, Default)] -pub struct PluginModuleBuilder { +pub struct PluginModuleBuilder { funcs: Vec<(String, sys::Function)>, globals: Vec<(String, sys::Global)>, memories: Vec<(String, sys::Memory)>, tables: Vec<(String, sys::Table)>, host_data: Option>, } -impl PluginModuleBuilder { +impl PluginModuleBuilder { /// Creates a new [PluginModuleBuilder]. pub fn new() -> Self { Self { @@ -385,7 +385,7 @@ impl PluginModuleBuilder { /// # Error /// /// If fail to create the [PluginModule], then an error is returned. - pub fn build(self, name: impl AsRef) -> WasmEdgeResult> { + pub fn build(self, name: impl AsRef) -> WasmEdgeResult { let mut inner = sys::plugin::PluginModule::create(name.as_ref(), self.host_data)?; // add func @@ -416,8 +416,8 @@ impl PluginModuleBuilder { /// /// An [PluginModule] instance is created with [PluginModuleBuilder](crate::plugin::PluginModuleBuilder). #[derive(Debug, Clone)] -pub struct PluginModule(pub(crate) sys::plugin::PluginModule); -impl PluginModule { +pub struct PluginModule(pub(crate) sys::plugin::PluginModule); +impl PluginModule { /// Returns the name of the plugin module instance. pub fn name(&self) -> &str { self.0.name() diff --git a/src/vm.rs b/src/vm.rs index b4fe86cd1..af297a22c 100644 --- a/src/vm.rs +++ b/src/vm.rs @@ -132,9 +132,9 @@ impl VmBuilder { if let Some(cfg) = vm.config.as_ref() { if cfg.wasi_enabled() { if let Ok(wasi_module) = sys::WasiModule::create(None, None, None) { - vm.executor.inner.register_import_object( + vm.executor.inner.register_wasi_instance( &vm.store.inner, - &sys::ImportObject::Wasi(wasi_module.clone()), + &sys::WasiInstance::Wasi(wasi_module.clone()), )?; vm.builtin_host_instances.insert( @@ -211,9 +211,9 @@ impl VmBuilder { )?; // register the AsyncWasiModule instance - vm.executor.inner.register_import_object( + vm.executor.inner.register_wasi_instance( &vm.store.inner, - &sys::ImportObject::AsyncWasi(wasi_module.clone()), + &sys::WasiInstance::AsyncWasi(wasi_module.clone()), )?; vm.builtin_host_instances.insert( @@ -874,8 +874,8 @@ mod tests { io::WasmVal, params, types::Val, - wat2wasm, AsInstance, CallingFrame, Global, GlobalType, ImportObjectBuilder, Memory, - MemoryType, Mutability, NeverType, RefType, Table, TableType, ValType, WasmValue, + wat2wasm, CallingFrame, Global, GlobalType, ImportObjectBuilder, Memory, MemoryType, + Mutability, NeverType, RefType, Table, TableType, ValType, WasmValue, }; #[test] diff --git a/src/wasi.rs b/src/wasi.rs index 769bea6fe..cf13aebc5 100644 --- a/src/wasi.rs +++ b/src/wasi.rs @@ -1,23 +1,20 @@ //! Defines wasi module instance types, including WasiInstance, WasiNnInstance, wasi-crypto instances. -cfg_if::cfg_if! { - if #[cfg(not(feature = "async"))] { - use crate::{ - AsInstance, Func, FuncType, Global, GlobalType, Memory, MemoryType, Table, TableType, - WasmEdgeResult, - }; - use wasmedge_sys::{AsImport, AsInstance as sys_as_instance_trait}; - } -} +use crate::WasmEdgeResult; /// Represents a wasi module instance. -#[cfg(not(feature = "async"))] #[derive(Debug, Clone)] pub struct WasiInstance { pub(crate) inner: wasmedge_sys::WasiModule, } -#[cfg(not(feature = "async"))] impl WasiInstance { + /// Returns the name of this exported [module instance](crate::Instance). + /// + /// If this [module instance](crate::Instance) is an active [instance](crate::Instance), return None. + pub fn name(&self) -> &str { + self.inner.name() + } + /// Initializes the WASI host module with the given parameters. /// /// # Arguments @@ -56,120 +53,3 @@ impl WasiInstance { self.inner.get_native_handler(fd) } } -#[cfg(not(feature = "async"))] -impl AsInstance for WasiInstance { - /// Returns the name of this exported [module instance](crate::Instance). - /// - /// If this [module instance](crate::Instance) is an active [instance](crate::Instance), return None. - fn name(&self) -> &str { - self.inner.name() - } - - /// Returns the count of the exported [function instances](crate::Func) in this [module instance](crate::Instance). - fn func_count(&self) -> usize { - self.inner.func_len() as usize - } - - /// Returns the names of the exported [function instances](crate::Func) in this [module instance](crate::Instance). - fn func_names(&self) -> Option> { - self.inner.func_names() - } - - /// Returns the exported [function instance](crate::Func) in this [module instance](crate::Instance) by the given function name. - /// - /// # Argument - /// - /// * `name` - the name of the target exported [function instance](crate::Func). - fn func(&self, name: impl AsRef) -> WasmEdgeResult { - let inner_func = self.inner.get_func(name.as_ref())?; - let ty: FuncType = inner_func.ty()?.into(); - - Ok(Func { - inner: inner_func, - name: Some(name.as_ref().into()), - mod_name: None, - ty, - }) - } - - /// Returns the count of the exported [global instances](crate::Global) in this [module instance](crate::Instance). - fn global_count(&self) -> usize { - self.inner.global_len() as usize - } - - /// Returns the names of the exported [global instances](crate::Global) in this [module instance](crate::Instance). - fn global_names(&self) -> Option> { - self.inner.global_names() - } - - /// Returns the exported [global instance](crate::Global) in this [module instance](crate::Instance) by the given global name. - /// - /// # Argument - /// - /// * `name` - the name of the target exported [global instance](crate::Global). - fn global(&self, name: impl AsRef) -> WasmEdgeResult { - let inner_global = self.inner.get_global(name.as_ref())?; - let ty: GlobalType = inner_global.ty()?.into(); - - Ok(Global { - inner: inner_global, - name: Some(name.as_ref().into()), - mod_name: None, - ty, - }) - } - - /// Returns the count of the exported [memory instances](crate::Memory) in this [module instance](crate::Instance). - fn memory_count(&self) -> usize { - self.inner.mem_len() as usize - } - - /// Returns the names of the exported [memory instances](crate::Memory) in this [module instance](crate::Instance). - fn memory_names(&self) -> Option> { - self.inner.mem_names() - } - - /// Returns the exported [memory instance](crate::Memory) in this [module instance](crate::Instance) by the given memory name. - /// - /// # Argument - /// - /// * `name` - the name of the target exported [memory instance](crate::Memory). - fn memory(&self, name: impl AsRef) -> WasmEdgeResult { - let inner_memory = self.inner.get_memory(name.as_ref())?; - let ty: MemoryType = inner_memory.ty()?.into(); - - Ok(Memory { - inner: inner_memory, - name: Some(name.as_ref().into()), - mod_name: None, - ty, - }) - } - - /// Returns the count of the exported [table instances](crate::Table) in this [module instance](crate::Instance). - fn table_count(&self) -> usize { - self.inner.table_len() as usize - } - - /// Returns the names of the exported [table instances](crate::Table) in this [module instance](crate::Instance). - fn table_names(&self) -> Option> { - self.inner.table_names() - } - - /// Returns the exported [table instance](crate::Table) in this [module instance](crate::Instance) by the given table name. - /// - /// # Argument - /// - /// * `name` - the name of the target exported [table instance](crate::Table). - fn table(&self, name: impl AsRef) -> WasmEdgeResult
{ - let inner_table = self.inner.get_table(name.as_ref())?; - let ty: TableType = inner_table.ty()?.into(); - - Ok(Table { - inner: inner_table, - name: Some(name.as_ref().into()), - mod_name: None, - ty, - }) - } -}