Function function1

Source
pub fn function1<Z, R, A>(f: Z) -> Function<Z, (A,), R>
where Z: FnMut(A) -> R,
Expand description

Wraps a type that implements FnMut so that it can be used by hlua.

This is needed because of a limitation in Rust’s inferrence system. Even though in practice functions and closures always have a fixed number of parameters, the FnMut trait of Rust was designed so that it allows calling the same closure with a varying number of parameters. The consequence however is that there is no way of inferring with the trait alone many parameters a function or closure expects.

Examples found in repository?
examples/rust_function.rs (line 9)
6fn main() {
7    let mut lua = hlua::Lua::new();
8
9    lua.set("foo", hlua::function1(|val: i32| val * 5));
10
11    let val: i32 = lua.execute(r#"return foo(8)"#).unwrap();
12    assert_eq!(val, 40);
13}