Trait rhai::Func[][src]

pub trait Func<ARGS, RET> {
    type Output;
    fn create_from_ast(self, ast: AST, entry_point: &str) -> Self::Output;
fn create_from_script(
        self,
        script: &str,
        entry_point: &str
    ) -> Result<Self::Output, ParseError>; }
Expand description

Trait to create a Rust closure from a script.

Not available under no_function.

Associated Types

Required methods

fn create_from_ast(self, ast: AST, entry_point: &str) -> Self::Output[src]

Create a Rust closure from an AST.

The Engine and AST are consumed and basically embedded into the closure.

Example

use rhai::{Engine, Func};               // use 'Func' for 'create_from_ast'

let engine = Engine::new();             // create a new 'Engine' just for this

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

// Func takes two type parameters:
//   1) a tuple made up of the types of the script function's parameters
//   2) the return type of the script function

// 'func' will have type Box<dyn Fn(i64, String) -> Result<bool, Box<EvalAltResult>>> and is callable!
let func = Func::<(i64, &str), bool>::create_from_ast(
//                ^^^^^^^^^^^ function parameter types in tuple

                                            engine, // the 'Engine' is consumed into the closure
                                            ast,    // the 'AST'
                                            "calc"  // the entry-point function name
                                        );

func(123, "hello")? == false;           // call the anonymous function

fn create_from_script(
    self,
    script: &str,
    entry_point: &str
) -> Result<Self::Output, ParseError>
[src]

Create a Rust closure from a script.

The Engine is consumed and basically embedded into the closure.

Example

use rhai::{Engine, Func};               // use 'Func' for 'create_from_script'

let engine = Engine::new();             // create a new 'Engine' just for this

let script = "fn calc(x, y) { x + len(y) < 42 }";

// Func takes two type parameters:
//   1) a tuple made up of the types of the script function's parameters
//   2) the return type of the script function

// 'func' will have type Box<dyn Fn(i64, String) -> Result<bool, Box<EvalAltResult>>> and is callable!
let func = Func::<(i64, &str), bool>::create_from_script(
//                ^^^^^^^^^^^ function parameter types in tuple

                                            engine, // the 'Engine' is consumed into the closure
                                            script, // the script, notice number of parameters must match
                                            "calc"  // the entry-point function name
                                        )?;

func(123, "hello")? == false;           // call the anonymous function

Implementors

impl<A: Variant + Clone, B: Variant + Clone, C: Variant + Clone, D: Variant + Clone, E: Variant + Clone, F: Variant + Clone, G: Variant + Clone, H: Variant + Clone, J: Variant + Clone, K: Variant + Clone, L: Variant + Clone, M: Variant + Clone, N: Variant + Clone, P: Variant + Clone, Q: Variant + Clone, R: Variant + Clone, S: Variant + Clone, T: Variant + Clone, U: Variant + Clone, V: Variant + Clone, RET: Variant + Clone> Func<(A, B, C, D, E, F, G, H, J, K, L, M, N, P, Q, R, S, T, U, V), RET> for Engine[src]

type Output = Box<dyn Fn(A, B, C, D, E, F, G, H, J, K, L, M, N, P, Q, R, S, T, U, V) -> Result<RET, Box<EvalAltResult>>>

fn create_from_ast(self, ast: AST, entry_point: &str) -> Self::Output[src]

fn create_from_script(
    self,
    script: &str,
    entry_point: &str
) -> Result<Self::Output, ParseError>
[src]

impl<B: Variant + Clone, C: Variant + Clone, D: Variant + Clone, E: Variant + Clone, F: Variant + Clone, G: Variant + Clone, H: Variant + Clone, J: Variant + Clone, K: Variant + Clone, L: Variant + Clone, M: Variant + Clone, N: Variant + Clone, P: Variant + Clone, Q: Variant + Clone, R: Variant + Clone, S: Variant + Clone, T: Variant + Clone, U: Variant + Clone, V: Variant + Clone, RET: Variant + Clone> Func<(B, C, D, E, F, G, H, J, K, L, M, N, P, Q, R, S, T, U, V), RET> for Engine[src]

type Output = Box<dyn Fn(B, C, D, E, F, G, H, J, K, L, M, N, P, Q, R, S, T, U, V) -> Result<RET, Box<EvalAltResult>>>

fn create_from_ast(self, ast: AST, entry_point: &str) -> Self::Output[src]

fn create_from_script(
    self,
    script: &str,
    entry_point: &str
) -> Result<Self::Output, ParseError>
[src]

impl<C: Variant + Clone, D: Variant + Clone, E: Variant + Clone, F: Variant + Clone, G: Variant + Clone, H: Variant + Clone, J: Variant + Clone, K: Variant + Clone, L: Variant + Clone, M: Variant + Clone, N: Variant + Clone, P: Variant + Clone, Q: Variant + Clone, R: Variant + Clone, S: Variant + Clone, T: Variant + Clone, U: Variant + Clone, V: Variant + Clone, RET: Variant + Clone> Func<(C, D, E, F, G, H, J, K, L, M, N, P, Q, R, S, T, U, V), RET> for Engine[src]

type Output = Box<dyn Fn(C, D, E, F, G, H, J, K, L, M, N, P, Q, R, S, T, U, V) -> Result<RET, Box<EvalAltResult>>>

fn create_from_ast(self, ast: AST, entry_point: &str) -> Self::Output[src]

fn create_from_script(
    self,
    script: &str,
    entry_point: &str
) -> Result<Self::Output, ParseError>
[src]

impl<D: Variant + Clone, E: Variant + Clone, F: Variant + Clone, G: Variant + Clone, H: Variant + Clone, J: Variant + Clone, K: Variant + Clone, L: Variant + Clone, M: Variant + Clone, N: Variant + Clone, P: Variant + Clone, Q: Variant + Clone, R: Variant + Clone, S: Variant + Clone, T: Variant + Clone, U: Variant + Clone, V: Variant + Clone, RET: Variant + Clone> Func<(D, E, F, G, H, J, K, L, M, N, P, Q, R, S, T, U, V), RET> for Engine[src]

type Output = Box<dyn Fn(D, E, F, G, H, J, K, L, M, N, P, Q, R, S, T, U, V) -> Result<RET, Box<EvalAltResult>>>

fn create_from_ast(self, ast: AST, entry_point: &str) -> Self::Output[src]

fn create_from_script(
    self,
    script: &str,
    entry_point: &str
) -> Result<Self::Output, ParseError>
[src]

impl<E: Variant + Clone, F: Variant + Clone, G: Variant + Clone, H: Variant + Clone, J: Variant + Clone, K: Variant + Clone, L: Variant + Clone, M: Variant + Clone, N: Variant + Clone, P: Variant + Clone, Q: Variant + Clone, R: Variant + Clone, S: Variant + Clone, T: Variant + Clone, U: Variant + Clone, V: Variant + Clone, RET: Variant + Clone> Func<(E, F, G, H, J, K, L, M, N, P, Q, R, S, T, U, V), RET> for Engine[src]

type Output = Box<dyn Fn(E, F, G, H, J, K, L, M, N, P, Q, R, S, T, U, V) -> Result<RET, Box<EvalAltResult>>>

fn create_from_ast(self, ast: AST, entry_point: &str) -> Self::Output[src]

fn create_from_script(
    self,
    script: &str,
    entry_point: &str
) -> Result<Self::Output, ParseError>
[src]

impl<F: Variant + Clone, G: Variant + Clone, H: Variant + Clone, J: Variant + Clone, K: Variant + Clone, L: Variant + Clone, M: Variant + Clone, N: Variant + Clone, P: Variant + Clone, Q: Variant + Clone, R: Variant + Clone, S: Variant + Clone, T: Variant + Clone, U: Variant + Clone, V: Variant + Clone, RET: Variant + Clone> Func<(F, G, H, J, K, L, M, N, P, Q, R, S, T, U, V), RET> for Engine[src]

type Output = Box<dyn Fn(F, G, H, J, K, L, M, N, P, Q, R, S, T, U, V) -> Result<RET, Box<EvalAltResult>>>

fn create_from_ast(self, ast: AST, entry_point: &str) -> Self::Output[src]

fn create_from_script(
    self,
    script: &str,
    entry_point: &str
) -> Result<Self::Output, ParseError>
[src]

impl<G: Variant + Clone, H: Variant + Clone, J: Variant + Clone, K: Variant + Clone, L: Variant + Clone, M: Variant + Clone, N: Variant + Clone, P: Variant + Clone, Q: Variant + Clone, R: Variant + Clone, S: Variant + Clone, T: Variant + Clone, U: Variant + Clone, V: Variant + Clone, RET: Variant + Clone> Func<(G, H, J, K, L, M, N, P, Q, R, S, T, U, V), RET> for Engine[src]

type Output = Box<dyn Fn(G, H, J, K, L, M, N, P, Q, R, S, T, U, V) -> Result<RET, Box<EvalAltResult>>>

fn create_from_ast(self, ast: AST, entry_point: &str) -> Self::Output[src]

fn create_from_script(
    self,
    script: &str,
    entry_point: &str
) -> Result<Self::Output, ParseError>
[src]

impl<H: Variant + Clone, J: Variant + Clone, K: Variant + Clone, L: Variant + Clone, M: Variant + Clone, N: Variant + Clone, P: Variant + Clone, Q: Variant + Clone, R: Variant + Clone, S: Variant + Clone, T: Variant + Clone, U: Variant + Clone, V: Variant + Clone, RET: Variant + Clone> Func<(H, J, K, L, M, N, P, Q, R, S, T, U, V), RET> for Engine[src]

type Output = Box<dyn Fn(H, J, K, L, M, N, P, Q, R, S, T, U, V) -> Result<RET, Box<EvalAltResult>>>

fn create_from_ast(self, ast: AST, entry_point: &str) -> Self::Output[src]

fn create_from_script(
    self,
    script: &str,
    entry_point: &str
) -> Result<Self::Output, ParseError>
[src]

impl<J: Variant + Clone, K: Variant + Clone, L: Variant + Clone, M: Variant + Clone, N: Variant + Clone, P: Variant + Clone, Q: Variant + Clone, R: Variant + Clone, S: Variant + Clone, T: Variant + Clone, U: Variant + Clone, V: Variant + Clone, RET: Variant + Clone> Func<(J, K, L, M, N, P, Q, R, S, T, U, V), RET> for Engine[src]

type Output = Box<dyn Fn(J, K, L, M, N, P, Q, R, S, T, U, V) -> Result<RET, Box<EvalAltResult>>>

fn create_from_ast(self, ast: AST, entry_point: &str) -> Self::Output[src]

fn create_from_script(
    self,
    script: &str,
    entry_point: &str
) -> Result<Self::Output, ParseError>
[src]

impl<K: Variant + Clone, L: Variant + Clone, M: Variant + Clone, N: Variant + Clone, P: Variant + Clone, Q: Variant + Clone, R: Variant + Clone, S: Variant + Clone, T: Variant + Clone, U: Variant + Clone, V: Variant + Clone, RET: Variant + Clone> Func<(K, L, M, N, P, Q, R, S, T, U, V), RET> for Engine[src]

type Output = Box<dyn Fn(K, L, M, N, P, Q, R, S, T, U, V) -> Result<RET, Box<EvalAltResult>>>

fn create_from_ast(self, ast: AST, entry_point: &str) -> Self::Output[src]

fn create_from_script(
    self,
    script: &str,
    entry_point: &str
) -> Result<Self::Output, ParseError>
[src]

impl<L: Variant + Clone, M: Variant + Clone, N: Variant + Clone, P: Variant + Clone, Q: Variant + Clone, R: Variant + Clone, S: Variant + Clone, T: Variant + Clone, U: Variant + Clone, V: Variant + Clone, RET: Variant + Clone> Func<(L, M, N, P, Q, R, S, T, U, V), RET> for Engine[src]

type Output = Box<dyn Fn(L, M, N, P, Q, R, S, T, U, V) -> Result<RET, Box<EvalAltResult>>>

fn create_from_ast(self, ast: AST, entry_point: &str) -> Self::Output[src]

fn create_from_script(
    self,
    script: &str,
    entry_point: &str
) -> Result<Self::Output, ParseError>
[src]

impl<M: Variant + Clone, N: Variant + Clone, P: Variant + Clone, Q: Variant + Clone, R: Variant + Clone, S: Variant + Clone, T: Variant + Clone, U: Variant + Clone, V: Variant + Clone, RET: Variant + Clone> Func<(M, N, P, Q, R, S, T, U, V), RET> for Engine[src]

type Output = Box<dyn Fn(M, N, P, Q, R, S, T, U, V) -> Result<RET, Box<EvalAltResult>>>

fn create_from_ast(self, ast: AST, entry_point: &str) -> Self::Output[src]

fn create_from_script(
    self,
    script: &str,
    entry_point: &str
) -> Result<Self::Output, ParseError>
[src]

impl<N: Variant + Clone, P: Variant + Clone, Q: Variant + Clone, R: Variant + Clone, S: Variant + Clone, T: Variant + Clone, U: Variant + Clone, V: Variant + Clone, RET: Variant + Clone> Func<(N, P, Q, R, S, T, U, V), RET> for Engine[src]

type Output = Box<dyn Fn(N, P, Q, R, S, T, U, V) -> Result<RET, Box<EvalAltResult>>>

fn create_from_ast(self, ast: AST, entry_point: &str) -> Self::Output[src]

fn create_from_script(
    self,
    script: &str,
    entry_point: &str
) -> Result<Self::Output, ParseError>
[src]

impl<P: Variant + Clone, Q: Variant + Clone, R: Variant + Clone, S: Variant + Clone, T: Variant + Clone, U: Variant + Clone, V: Variant + Clone, RET: Variant + Clone> Func<(P, Q, R, S, T, U, V), RET> for Engine[src]

type Output = Box<dyn Fn(P, Q, R, S, T, U, V) -> Result<RET, Box<EvalAltResult>>>

fn create_from_ast(self, ast: AST, entry_point: &str) -> Self::Output[src]

fn create_from_script(
    self,
    script: &str,
    entry_point: &str
) -> Result<Self::Output, ParseError>
[src]

impl<Q: Variant + Clone, R: Variant + Clone, S: Variant + Clone, T: Variant + Clone, U: Variant + Clone, V: Variant + Clone, RET: Variant + Clone> Func<(Q, R, S, T, U, V), RET> for Engine[src]

type Output = Box<dyn Fn(Q, R, S, T, U, V) -> Result<RET, Box<EvalAltResult>>>

fn create_from_ast(self, ast: AST, entry_point: &str) -> Self::Output[src]

fn create_from_script(
    self,
    script: &str,
    entry_point: &str
) -> Result<Self::Output, ParseError>
[src]

impl<R: Variant + Clone, S: Variant + Clone, T: Variant + Clone, U: Variant + Clone, V: Variant + Clone, RET: Variant + Clone> Func<(R, S, T, U, V), RET> for Engine[src]

type Output = Box<dyn Fn(R, S, T, U, V) -> Result<RET, Box<EvalAltResult>>>

fn create_from_ast(self, ast: AST, entry_point: &str) -> Self::Output[src]

fn create_from_script(
    self,
    script: &str,
    entry_point: &str
) -> Result<Self::Output, ParseError>
[src]

impl<RET: Variant + Clone> Func<(), RET> for Engine[src]

type Output = Box<dyn Fn() -> Result<RET, Box<EvalAltResult>>>

fn create_from_ast(self, ast: AST, entry_point: &str) -> Self::Output[src]

fn create_from_script(
    self,
    script: &str,
    entry_point: &str
) -> Result<Self::Output, ParseError>
[src]

impl<S: Variant + Clone, T: Variant + Clone, U: Variant + Clone, V: Variant + Clone, RET: Variant + Clone> Func<(S, T, U, V), RET> for Engine[src]

type Output = Box<dyn Fn(S, T, U, V) -> Result<RET, Box<EvalAltResult>>>

fn create_from_ast(self, ast: AST, entry_point: &str) -> Self::Output[src]

fn create_from_script(
    self,
    script: &str,
    entry_point: &str
) -> Result<Self::Output, ParseError>
[src]

impl<T: Variant + Clone, U: Variant + Clone, V: Variant + Clone, RET: Variant + Clone> Func<(T, U, V), RET> for Engine[src]

type Output = Box<dyn Fn(T, U, V) -> Result<RET, Box<EvalAltResult>>>

fn create_from_ast(self, ast: AST, entry_point: &str) -> Self::Output[src]

fn create_from_script(
    self,
    script: &str,
    entry_point: &str
) -> Result<Self::Output, ParseError>
[src]

impl<U: Variant + Clone, V: Variant + Clone, RET: Variant + Clone> Func<(U, V), RET> for Engine[src]

type Output = Box<dyn Fn(U, V) -> Result<RET, Box<EvalAltResult>>>

fn create_from_ast(self, ast: AST, entry_point: &str) -> Self::Output[src]

fn create_from_script(
    self,
    script: &str,
    entry_point: &str
) -> Result<Self::Output, ParseError>
[src]

impl<V: Variant + Clone, RET: Variant + Clone> Func<(V,), RET> for Engine[src]

type Output = Box<dyn Fn(V) -> Result<RET, Box<EvalAltResult>>>

fn create_from_ast(self, ast: AST, entry_point: &str) -> Self::Output[src]

fn create_from_script(
    self,
    script: &str,
    entry_point: &str
) -> Result<Self::Output, ParseError>
[src]