diff options
author | Alex Orlenko <zxteam@protonmail.com> | 2024-06-02 00:51:24 +0100 |
---|---|---|
committer | Alex Orlenko <zxteam@protonmail.com> | 2024-06-24 22:46:59 +0100 |
commit | dc12da49d6216fe280b1cf511172ffad508ac44d (patch) | |
tree | 0b53b66965f42b5c8e4cae8d7abb87844009408a /mlua_derive/src | |
parent | fc9475b4959ce23e3bb420b42a95543e4f55bac2 (diff) | |
download | mlua-dc12da49d6216fe280b1cf511172ffad508ac44d.zip |
Refactor: WIP
Diffstat (limited to 'mlua_derive/src')
-rw-r--r-- | mlua_derive/src/from_lua.rs | 4 | ||||
-rw-r--r-- | mlua_derive/src/lib.rs | 17 |
2 files changed, 9 insertions, 12 deletions
diff --git a/mlua_derive/src/from_lua.rs b/mlua_derive/src/from_lua.rs index 3d4e4ed..8d0b683 100644 --- a/mlua_derive/src/from_lua.rs +++ b/mlua_derive/src/from_lua.rs @@ -15,9 +15,9 @@ pub fn from_lua(input: TokenStream) -> TokenStream { }; quote! { - impl #impl_generics ::mlua::FromLua<'_> for #ident #ty_generics #where_clause { + impl #impl_generics ::mlua::FromLua for #ident #ty_generics #where_clause { #[inline] - fn from_lua(value: ::mlua::Value<'_>, _: &'_ ::mlua::Lua) -> ::mlua::Result<Self> { + fn from_lua(value: ::mlua::Value, _: &::mlua::Lua) -> ::mlua::Result<Self> { match value { ::mlua::Value::UserData(ud) => Ok(ud.borrow::<Self>()?.clone()), _ => Err(::mlua::Error::FromLuaConversionError { diff --git a/mlua_derive/src/lib.rs b/mlua_derive/src/lib.rs index 74605cb..07209be 100644 --- a/mlua_derive/src/lib.rs +++ b/mlua_derive/src/lib.rs @@ -99,15 +99,14 @@ pub fn chunk(input: TokenStream) -> TokenStream { use ::std::borrow::Cow; use ::std::cell::Cell; use ::std::io::Result as IoResult; - use ::std::marker::PhantomData; - struct InnerChunk<'lua, F: FnOnce(&'lua Lua) -> Result<Table<'lua>>>(Cell<Option<F>>, PhantomData<&'lua ()>); + struct InnerChunk<F: FnOnce(&Lua) -> Result<Table>>(Cell<Option<F>>); - impl<'lua, F> AsChunk<'lua, 'static> for InnerChunk<'lua, F> + impl<F> AsChunk<'static> for InnerChunk<F> where - F: FnOnce(&'lua Lua) -> Result<Table<'lua>>, + F: FnOnce(&Lua) -> Result<Table>, { - fn environment(&self, lua: &'lua Lua) -> Result<Option<Table<'lua>>> { + fn environment(&self, lua: &Lua) -> Result<Option<Table>> { if #caps_len > 0 { if let Some(make_env) = self.0.take() { return make_env(lua).map(Some); @@ -125,9 +124,7 @@ pub fn chunk(input: TokenStream) -> TokenStream { } } - fn annotate<'a, F: FnOnce(&'a Lua) -> Result<Table<'a>>>(f: F) -> F { f } - - let make_env = annotate(move |lua: &Lua| -> Result<Table> { + let make_env = move |lua: &Lua| -> Result<Table> { let globals = lua.globals(); let env = lua.create_table()?; let meta = lua.create_table()?; @@ -139,9 +136,9 @@ pub fn chunk(input: TokenStream) -> TokenStream { env.set_metatable(Some(meta)); Ok(env) - }); + }; - InnerChunk(Cell::new(Some(make_env)), PhantomData) + InnerChunk(Cell::new(Some(make_env))) }}; wrapped_code.into() |