pub fn from_buffer(&self, buffer: impl AsRef<[u8]>) -> WasmEdgeResult<Module> {
        let mut mod_ctx: *mut wasmedge::WasmEdge_ASTModuleContext = std::ptr::null_mut();

        unsafe {
            let ptr = libc::malloc(buffer.as_ref().len());
            let dst = ::core::slice::from_raw_parts_mut(
                ptr.cast::<std::mem::MaybeUninit<u8>>(),
                buffer.as_ref().len(),
            );
            let src = ::core::slice::from_raw_parts(
                buffer.as_ref().as_ptr().cast::<std::mem::MaybeUninit<u8>>(),
                buffer.as_ref().len(),
            );
            dst.copy_from_slice(src);

            check(wasmedge::WasmEdge_LoaderParseFromBuffer(
                self.inner.0,
                &mut mod_ctx,
                ptr as *const u8,
                buffer.as_ref().len() as u32,
            ))?;

            libc::free(ptr as *mut libc::c_void);
        }

        match mod_ctx.is_null() {
            true => Err(WasmEdgeError::ModuleCreate),
            false => Ok(Module {
                inner: InnerModule(mod_ctx),
            }),
        }
    }
/// Loads a WASM module from a buffer.
///
/// # Arguments
///
/// - `buffer` specifies a WASM buffer.
///
/// # Error
///
/// If fail to load, then an error is returned.
///
/// # Example
///
/// ```ignore
/// let buffer = b"\0asm\x01\0\0\0";
/// let module = loader.from_buffer(&buffer)?;
/// ```
///
/// Note that the text format is not accepted:
///
/// ```ignore
/// assert!(loader.from_buffer(b"(module)").is_err());
/// ```
Loads a WASM module from a buffer.
Loads a WASM module from a buffer .
pub fn from_buffer(&self, buffer: impl AsRef<[u8]>) -> WasmEdgeResult<Module> {
        let mut mod_ctx: *mut wasmedge::WasmEdge_ASTModuleContext = std::ptr::null_mut();
        unsafe {
            let ptr = libc::malloc(buffer.as_ref().len());
            let dst = ::core::slice::from_raw_parts_mut(
                ptr.cast::<std::mem::MaybeUninit<u8>>(),
                buffer.as_ref().len(),
            );
            let src = ::core::slice::from_raw_parts(
                buffer.as_ref().as_ptr().cast::<std::mem::MaybeUninit<u8>>(),
                buffer.as_ref().len(),
            );
            dst.copy_from_slice(src);
            check(wasmedge::WasmEdge_LoaderParseFromBuffer(
                self.inner.0,
                &mut mod_ctx,
                ptr as *const u8,
                buffer.as_ref().len() as u32,
            ))?;
            libc::free(ptr as *mut libc::c_void);
        }
        match mod_ctx.is_null() {
            true => Err(WasmEdgeError::ModuleCreate),
            false => Ok(Module {
                inner: InnerModule(mod_ctx),
            }),
        }
    }
pub fn from_buffer ( & self , buffer : impl AsRef < [ u8 ] > ) -> WasmEdgeResult < Module > { let mut mod_ctx : * mut wasmedge :: WasmEdge_ASTModuleContext = std :: ptr :: null_mut ( ) ; unsafe { let ptr = libc :: malloc ( buffer . as_ref ( ) . len ( ) ) ; let dst = :: core :: slice :: from_raw_parts_mut ( ptr . cast :: < std :: mem :: MaybeUninit < u8 > > ( ) , buffer . as_ref ( ) . len ( ) , ) ; let src = :: core :: slice :: from_raw_parts ( buffer . as_ref ( ) . as_ptr ( ) . cast :: < std :: mem :: MaybeUninit < u8 > > ( ) , buffer . as_ref ( ) . len ( ) , ) ; dst . copy_from_slice ( src ) ; check ( wasmedge :: WasmEdge_LoaderParseFromBuffer ( self . inner . 0 , & mut mod_ctx , ptr as * const u8 , buffer . as_ref ( ) . len ( ) as u32 , ) ) ? ; libc :: free ( ptr as * mut libc :: c_void ) ; } match mod_ctx . is_null ( ) { true => Err ( WasmEdgeError :: ModuleCreate ) , false => Ok ( Module { inner : InnerModule ( mod_ctx ) , } ) , } }
Loads a WASM module from a buffer.
Loads a WASM module from a buffer .
&self
buffer
impl AsRef<[u8]>
&self
buffer
impl AsRef<[u8]>
specifies a WASM buffer.
specifies a WASM buffer .
error
If fail to load, then an error is returned.
If fail to load then an error is returned .
example


Note that the text format is not accepted.


Note that the text format is not accepted .