pub struct Function { /* private fields */ }
Expand description
Implementations§
Source§impl Function
impl Function
Sourcepub unsafe fn create_sync_func<T>(
ty: &FuncType,
real_fn: SyncFn<T>,
data: *mut T,
cost: u64,
) -> WasmEdgeResult<Self>
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
- If fail to create a Function, then WasmEdgeError::Func(FuncError::Create) is returned.
§Safety
The lifetime of data
must be greater than that of Function
itself.
Sourcepub unsafe fn create_with_custom_wrapper(
ty: &FuncType,
fn_wrapper: CustomFnWrapper,
real_fn: *mut c_void,
data: *mut c_void,
cost: u64,
) -> WasmEdgeResult<Self>
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
- If fail to create a Function, then WasmEdgeError::Func(FuncError::Create) is returned.
§Safety
Notice that the caller should guarantee the life cycle of both the real_fn
and the data
object.
Sourcepub unsafe fn as_ptr(&self) -> *mut WasmEdge_FunctionInstanceContext
pub unsafe fn as_ptr(&self) -> *mut WasmEdge_FunctionInstanceContext
§Safety
The lifetime of the returned pointer must not exceed that of the object itself.
Sourcepub unsafe fn from_raw(ctx: *mut WasmEdge_FunctionInstanceContext) -> Self
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 AsMut<Function> for AsyncFunction
Available on crate feature async
and Linux only.
impl AsMut<Function> for AsyncFunction
async
and Linux only.Source§impl AsRef<Function> for AsyncFunction
Available on crate feature async
and Linux only.
impl AsRef<Function> for AsyncFunction
async
and Linux only.