use mlua::{FromLuaMulti, Function, IntoLuaMulti, Lua, Result}; use super::ownedfunction::OwnedFunction; pub trait Runnable where Self: Send, R: ?Sized { fn run<'lua>(&self, arg: A, lua: &'lua Lua) -> Result where A: IntoLuaMulti<'lua>, R: FromLuaMulti<'lua>; } impl Runnable for T where T: Fn(A) -> R, Self: Send, R: ?Sized { fn run<'lua>(&self, arg: A, _: &'lua Lua) -> Result where A: IntoLuaMulti<'lua>, R: FromLuaMulti<'lua>, { Ok(self(arg)) } } impl Runnable for OwnedFunction where Self: Send, R: ?Sized { fn run<'lua>(&self, arg: A, lua: &'lua Lua) -> Result where A: IntoLuaMulti<'lua>, R: FromLuaMulti<'lua>, { let func: Function = self.get(lua); func.call::(arg) } }