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!
] uses this method to generate the
type signature for functions exported by #[export]
.
Implementations on Foreign Types§
Source§impl<'a, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, R> NativeFunction<'a> for fn(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12) -> R
impl<'a, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, R> NativeFunction<'a> for fn(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12) -> R
Source§impl<'a, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, R> NativeFunction<'a> for fn(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11) -> R
impl<'a, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, R> NativeFunction<'a> for fn(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11) -> R
Source§impl<'a, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, R> NativeFunction<'a> for fn(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10) -> R
impl<'a, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, R> NativeFunction<'a> for fn(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10) -> R
Source§impl<'a, A1, A2, A3, A4, A5, A6, A7, A8, A9, R> NativeFunction<'a> for fn(A1, A2, A3, A4, A5, A6, A7, A8, A9) -> R
impl<'a, A1, A2, A3, A4, A5, A6, A7, A8, A9, R> NativeFunction<'a> for fn(A1, A2, A3, A4, A5, A6, A7, A8, A9) -> R
Source§impl<'a, A1, A2, A3, A4, A5, A6, A7, A8, R> NativeFunction<'a> for fn(A1, A2, A3, A4, A5, A6, A7, A8) -> R
impl<'a, A1, A2, A3, A4, A5, A6, A7, A8, R> NativeFunction<'a> for fn(A1, A2, A3, A4, A5, A6, A7, A8) -> R
Source§impl<'a, A1, A2, A3, A4, A5, A6, A7, R> NativeFunction<'a> for fn(A1, A2, A3, A4, A5, A6, A7) -> R
impl<'a, A1, A2, A3, A4, A5, A6, A7, R> NativeFunction<'a> for fn(A1, A2, A3, A4, A5, A6, A7) -> R
Source§impl<'a, A1, A2, A3, A4, A5, A6, R> NativeFunction<'a> for fn(A1, A2, A3, A4, A5, A6) -> R
impl<'a, A1, A2, A3, A4, A5, A6, R> NativeFunction<'a> for fn(A1, A2, A3, A4, A5, A6) -> R
Source§impl<'a, A1, A2, A3, A4, A5, R> NativeFunction<'a> for fn(A1, A2, A3, A4, A5) -> R
impl<'a, A1, A2, A3, A4, A5, R> NativeFunction<'a> for fn(A1, A2, A3, A4, A5) -> R
Source§impl<'a, A1, A2, A3, A4, R> NativeFunction<'a> for fn(A1, A2, A3, A4) -> R
impl<'a, A1, A2, A3, A4, R> NativeFunction<'a> for fn(A1, A2, A3, A4) -> R
Source§impl<'a, A1, A2, A3, R> NativeFunction<'a> for fn(A1, A2, A3) -> R
impl<'a, A1, A2, A3, R> NativeFunction<'a> for fn(A1, A2, A3) -> R
Source§impl<'a, A1, A2, R> NativeFunction<'a> for fn(A1, A2) -> R
impl<'a, A1, A2, R> NativeFunction<'a> for fn(A1, A2) -> R
Source§impl<'a, A1, R> NativeFunction<'a> for fn(A1) -> R
impl<'a, A1, R> NativeFunction<'a> for fn(A1) -> R
Source§impl<'a, R> NativeFunction<'a> for fn() -> Rwhere
R: IntoArg,
impl<'a, R> NativeFunction<'a> for fn() -> Rwhere
R: IntoArg,
Source§impl<'a: 'b, 'b> NativeFunction<'a> for fn(&'b [MArgument], MArgument)
Implement NativeFunction
for functions that use raw MArgument
s for their
arguments and return value.
impl<'a: 'b, 'b> NativeFunction<'a> for fn(&'b [MArgument], MArgument)
Implement NativeFunction
for functions that use raw MArgument
s 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]