Specify the types exactly in the scary transmute
If I happen to change the definition of the Callback type alias, instead of creating a potentially arbitrary transmute, it will now instead fail to compile.
This commit is contained in:
parent
a91e3ed411
commit
da1e1625b3
12
src/lua.rs
12
src/lua.rs
|
@ -1066,15 +1066,17 @@ impl<'lua, 'scope> Scope<'lua, 'scope> {
|
||||||
R: ToLuaMulti<'callback>,
|
R: ToLuaMulti<'callback>,
|
||||||
F: 'scope + Fn(&'callback Lua, A) -> Result<R>,
|
F: 'scope + Fn(&'callback Lua, A) -> Result<R>,
|
||||||
{
|
{
|
||||||
unsafe {
|
|
||||||
let f: Box<
|
let f: Box<
|
||||||
Fn(&'callback Lua, MultiValue<'callback>) -> Result<MultiValue<'callback>> + 'scope,
|
Fn(&'callback Lua, MultiValue<'callback>) -> Result<MultiValue<'callback>> + 'scope,
|
||||||
> = Box::new(move |lua, args| {
|
> = Box::new(move |lua, args| func(lua, A::from_lua_multi(args, lua)?)?.to_lua_multi(lua));
|
||||||
func(lua, A::from_lua_multi(args, lua)?)?.to_lua_multi(lua)
|
|
||||||
});
|
|
||||||
|
|
||||||
|
unsafe {
|
||||||
// SCARY, we are transmuting the 'scope lifetime to 'static.
|
// SCARY, we are transmuting the 'scope lifetime to 'static.
|
||||||
let mut f = self.lua.create_callback_function(mem::transmute(f))?;
|
let f: Box<
|
||||||
|
Fn(&'callback Lua, MultiValue<'callback>) -> Result<MultiValue<'callback>>,
|
||||||
|
> = mem::transmute(f);
|
||||||
|
|
||||||
|
let mut f = self.lua.create_callback_function(f)?;
|
||||||
|
|
||||||
f.0.drop_unref = false;
|
f.0.drop_unref = false;
|
||||||
let mut destructors = self.destructors.borrow_mut();
|
let mut destructors = self.destructors.borrow_mut();
|
||||||
|
|
Loading…
Reference in New Issue