pub trait NativeFunction<'a> {
// Required methods
unsafe fn call(&self, args: &'a [MArgument], ret: MArgument);
fn signature(&self) -> Result<(Vec<Expr>, Expr), String>;
}Expand description
Trait implemented for any function whose parameters and return type are native
LibraryLink MArgument types.
#[export] can only be used with functions that implement this trait.
A function implements this trait if all of its parameters implement FromArg and
its return type implements IntoArg.
Functions that pass their arguments and return value using a [wstp::Link] do not
implement this trait. See [WstpFunction].
Required Methods§
Sourceunsafe fn call(&self, args: &'a [MArgument], ret: MArgument)
unsafe fn call(&self, args: &'a [MArgument], ret: MArgument)
Call the function using the raw LibraryLink MArgument fields.
Sourcefn signature(&self) -> Result<(Vec<Expr>, Expr), String>
fn signature(&self) -> Result<(Vec<Expr>, Expr), String>
Get the type signature of this function, suitable for use in
LibraryFunctionLoad[_, _, parameters, ret].
See also FromArg::parameter_type() and IntoArg::return_type().
The function generated by [generate_loader!][crate::generate_loader] uses this method to generate the
type signature for functions exported by #[export].
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl<'a, 'b> NativeFunction<'a> for fn(&'b [MArgument], MArgument)where
'a: 'b,
Implement NativeFunction for functions that use raw MArguments for their
arguments and return value.
impl<'a, 'b> NativeFunction<'a> for fn(&'b [MArgument], MArgument)where
'a: 'b,
Implement NativeFunction for functions that use raw MArguments for their
arguments and return value.
§Example
use wolfram_library_link::{self as wll, sys::MArgument, FromArg};
#[wll::export]
fn raw_add2(args: &[MArgument], ret: MArgument) {
let x = unsafe { i64::from_arg(&args[0]) };
let y = unsafe { i64::from_arg(&args[1]) };
unsafe {
*ret.integer = x + y;
}
}LibraryFunctionLoad["...", "raw_add2", {Integer, Integer}, Integer]