pub struct FnPtr { /* private fields */ }
Expand description

A general function pointer, which may carry additional (i.e. curried) argument values to be passed onto a function during a call.

Implementations

👎Deprecated since 1.8.0:

use curry().len() instead

Get the number of curried arguments.

Deprecated

This method is deprecated. Use curry().len() instead.

This method will be removed in the next major version.

👎Deprecated since 1.3.0:

use call_within_context or call_raw instead

Call the function pointer with curried arguments (if any). The function may be script-defined (not available under no_function) or native Rust.

This method is intended for calling a function pointer that is passed into a native Rust function as an argument. Therefore, the AST is NOT evaluated before calling the function.

Deprecated

This method is deprecated. Use call_within_context or call_raw instead.

This method will be removed in the next major version.

Create a new function pointer.

Get the name of the function.

Get the curried arguments.

Add a new curried argument.

Set curried arguments to the function pointer.

Is the function pointer curried?

Does the function pointer refer to an anonymous function?

Not available under no_function.

Call the function pointer with curried arguments (if any). The function may be script-defined (not available under no_function) or native Rust.

This method is intended for calling a function pointer directly, possibly on another Engine. Therefore, the AST is NOT evaluated before calling the function.

Example
use rhai::{Engine, FnPtr};

let engine = Engine::new();

let ast = engine.compile("fn foo(x, y) { len(x) + y }")?;

let mut fn_ptr = FnPtr::new("foo")?;

// Curry values into the function pointer
fn_ptr.set_curry(vec!["abc".into()]);

// Values are only needed for non-curried parameters
let result: i64 = fn_ptr.call(&engine, &ast, ( 39_i64, ) )?;

assert_eq!(result, 42);

Call the function pointer with curried arguments (if any). The function may be script-defined (not available under no_function) or native Rust.

This method is intended for calling a function pointer that is passed into a native Rust function as an argument. Therefore, the AST is NOT evaluated before calling the function.

Call the function pointer with curried arguments (if any). The function may be script-defined (not available under no_function) or native Rust.

This method is intended for calling a function pointer that is passed into a native Rust function as an argument. Therefore, the AST is NOT evaluated before calling the function.

WARNING - Low Level API

This function is very low level.

Arguments

All the arguments are consumed, meaning that they’re replaced by (). This is to avoid unnecessarily cloning the arguments.

Do not use the arguments after this call. If they are needed afterwards, clone them before calling this function.

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Formats the value using the given formatter. Read more
Converts to this type from the input type.
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.