From ce7e8e61fd9849695527b3c0b04db8f7c7c94db1 Mon Sep 17 00:00:00 2001 From: kyren Date: Sun, 11 Feb 2018 08:51:17 -0500 Subject: shave this yak some more, make `Callback` type alias have two lifetimes --- src/lua.rs | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'src/lua.rs') diff --git a/src/lua.rs b/src/lua.rs index 9dcd438..9526301 100644 --- a/src/lua.rs +++ b/src/lua.rs @@ -973,7 +973,7 @@ impl Lua { fn create_callback_function<'lua, 'callback>( &'lua self, - func: Callback<'callback>, + func: Callback<'callback, 'static>, ) -> Result> { unsafe extern "C" fn callback_call_impl(state: *mut ffi::lua_State) -> c_int { callback_error(state, || { @@ -1066,16 +1066,11 @@ impl<'lua, 'scope> Scope<'lua, 'scope> { R: ToLuaMulti<'callback>, F: 'scope + Fn(&'callback Lua, A) -> Result, { - let f: Box< - Fn(&'callback Lua, MultiValue<'callback>) -> Result> + 'scope, - > = Box::new(move |lua, args| func(lua, A::from_lua_multi(args, lua)?)?.to_lua_multi(lua)); - unsafe { - // SCARY, we are transmuting the 'scope lifetime to 'static. - let f: Box< - Fn(&'callback Lua, MultiValue<'callback>) -> Result>, - > = mem::transmute(f); - + let f = Box::new(move |lua, args| { + func(lua, A::from_lua_multi(args, lua)?)?.to_lua_multi(lua) + }); + let f = mem::transmute::, Callback<'callback, 'static>>(f); let mut f = self.lua.create_callback_function(f)?; f.0.drop_unref = false; -- cgit v1.2.3