Struct wasmedge_sys::Function

source ·
pub struct Function { /* private fields */ }
Expand description

Defines a host function.

A WasmEdge Function defines a WebAssembly host function described by its type. A host function is a closure of the original function defined in either the host or the WebAssembly module.

Implementations§

source§

impl Function

source

pub unsafe fn create_sync_func<T>( ty: &FuncType, real_fn: SyncFn<T>, data: *mut T, cost: u64 ) -> WasmEdgeResult<Self>

Creates a host function with the given function type.

N.B. that this function is used for thread-safe scenarios.

§Arguments
  • ty - The types of the arguments and returns of the target function.

  • real_fn - The pointer to the target function.

  • data - The host context data used in this function.

  • cost - The function cost in the Statistics. Pass 0 if the calculation is not needed.

§Error
§Safety

The lifetime of data must be greater than that of Function itself.

source

pub unsafe fn create_with_custom_wrapper( ty: &FuncType, fn_wrapper: CustomFnWrapper, real_fn: *mut c_void, data: *mut c_void, cost: u64 ) -> WasmEdgeResult<Self>

Creates a host function with the given function type and the custom function wrapper.

§Arguments
  • ty - The types of the arguments and returns of the target function.

  • fn_wrapper - The custom function wrapper.

  • real_fn - The pointer to the target function.

  • data - The pointer to the host context data used in this function.

  • cost - The function cost in the Statistics. Pass 0 if the calculation is not needed.

§Error
§Safety

Notice that the caller should guarantee the life cycle of both the real_fn and the data object.

source

pub unsafe fn as_ptr(&self) -> *mut WasmEdge_FunctionInstanceContext

§Safety

The lifetime of the returned pointer must not exceed that of the object itself.

source

pub unsafe fn from_raw(ctx: *mut WasmEdge_FunctionInstanceContext) -> Self

§Safety

This function will take over the lifetime management of ctx, so do not call ffi::WasmEdge_FunctionInstanceDelete on ctx after this.

Trait Implementations§

source§

impl AsFunc for Function

source§

impl AsMut<Function> for AsyncFunction

Available on crate feature async and Linux only.
source§

fn as_mut(&mut self) -> &mut Function

Converts this type into a mutable reference of the (usually inferred) input type.
source§

impl AsRef<Function> for AsyncFunction

Available on crate feature async and Linux only.
source§

fn as_ref(&self) -> &Function

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl Debug for Function

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Drop for Function

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.