wasmedge_sys::instance::function

Struct 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>,

Source§

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>,

Source§

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.