fn instantiate(&self, py: Python) -> PyResult<Py<Instance>> {
        let imports = imports! {};

        // Instantiate the module.
        let instance = match self.module.instantiate(&imports) {
            Ok(instance) => Rc::new(instance),
            Err(e) => {
                return Err(RuntimeError::py_err(format!(
                    "Failed to instantiate the module:\n    {}",
                    e
                )))
            }
        };

        let exports = instance.exports();

        // Collect the exported functions, globals and memory from the
        // WebAssembly module.
        let mut exported_functions = Vec::new();
        let mut exported_globals = Vec::new();
        let mut exported_memory = None;

        for (export_name, export) in exports {
            match export {
                Export::Function { .. } => exported_functions.push(export_name),
                Export::Global(global) => exported_globals.push((export_name, Rc::new(global))),
                Export::Memory(memory) if exported_memory.is_none() => {
                    exported_memory = Some(Rc::new(memory))
                }
                _ => (),
            }
        }

        // Instantiate the `Instance` Python class.
        Ok(Py::new(
            py,
            Instance {
                exports: Py::new(
                    py,
                    ExportedFunctions {
                        instance: instance.clone(),
                        functions: exported_functions,
                    },
                )?,
                memory: match exported_memory {
                    Some(memory) => Some(Py::new(py, Memory { memory })?),
                    None => None,
                },
                globals: Py::new(
                    py,
                    ExportedGlobals {
                        globals: exported_globals,
                    },
                )?,
            },
        )?)
    }
// Instantiate the module into an `Instance` Python object.
Instantiate the module into an `Instance` Python object.
Instantiate the module into an ` Instance ` Python object .
fn instantiate(&self, py: Python) -> PyResult<Py<Instance>> {
        let imports = imports! {};
        // Instantiate the module.
        let instance = match self.module.instantiate(&imports) {
            Ok(instance) => Rc::new(instance),
            Err(e) => {
                return Err(RuntimeError::py_err(format!(
                    "Failed to instantiate the module:\n    {}",
                    e
                )))
            }
        };
        let exports = instance.exports();
        // Collect the exported functions, globals and memory from the
        // WebAssembly module.
        let mut exported_functions = Vec::new();
        let mut exported_globals = Vec::new();
        let mut exported_memory = None;
        for (export_name, export) in exports {
            match export {
                Export::Function { .. } => exported_functions.push(export_name),
                Export::Global(global) => exported_globals.push((export_name, Rc::new(global))),
                Export::Memory(memory) if exported_memory.is_none() => {
                    exported_memory = Some(Rc::new(memory))
                }
                _ => (),
            }
        }
        // Instantiate the `Instance` Python class.
        Ok(Py::new(
            py,
            Instance {
                exports: Py::new(
                    py,
                    ExportedFunctions {
                        instance: instance.clone(),
                        functions: exported_functions,
                    },
                )?,
                memory: match exported_memory {
                    Some(memory) => Some(Py::new(py, Memory { memory })?),
                    None => None,
                },
                globals: Py::new(
                    py,
                    ExportedGlobals {
                        globals: exported_globals,
                    },
                )?,
            },
        )?)
    }
fn instantiate ( & self , py : Python ) -> PyResult < Py < Instance > > { let imports = imports ! { } ; // Instantiate the module. let instance = match self . module . instantiate ( & imports ) { Ok ( instance ) => Rc :: new ( instance ) , Err ( e ) => { return Err ( RuntimeError :: py_err ( format ! ( " \n " e ) ) ) } } ; let exports = instance . exports ( ) ; // Collect the exported functions, globals and memory from the // WebAssembly module. let mut exported_functions = Vec :: new ( ) ; let mut exported_globals = Vec :: new ( ) ; let mut exported_memory = None ; for ( export_name , export ) in exports { match export { Export :: Function { .. } => exported_functions . push ( export_name ) , Export :: Global ( global ) => exported_globals . push ( ( export_name , Rc :: new ( global ) ) ) , Export :: Memory ( memory ) if exported_memory . is_none ( ) => { exported_memory = Some ( Rc :: new ( memory ) ) } _ => ( ) , } } // Instantiate the `Instance` Python class. Ok ( Py :: new ( py , Instance { exports : Py :: new ( py , ExportedFunctions { instance : instance . clone ( ) , functions : exported_functions , } , ) ? , memory : match exported_memory { Some ( memory ) => Some ( Py :: new ( py , Memory { memory } ) ? ) , None => None , } , globals : Py :: new ( py , ExportedGlobals { globals : exported_globals , } , ) ? , } , ) ? ) }
Instantiate the module into an `Instance` Python object.
Instantiate the module into an ` Instance ` Python object .
&self
py
Python
&self
py
Python