diff options
author | Alex Orlenko <zxteam@protonmail.com> | 2024-01-25 10:26:43 +0000 |
---|---|---|
committer | Alex Orlenko <zxteam@protonmail.com> | 2024-01-25 10:26:43 +0000 |
commit | 145c5b316b335b81b8b537641806b63193803761 (patch) | |
tree | c0f38ce11e32f1ce2c11b9d6a6193fbea99b0138 /mlua_derive/src | |
parent | e97e69a3091db7131c510a0c405402c44cb94079 (diff) | |
download | mlua-145c5b316b335b81b8b537641806b63193803761.zip |
Fix `FromLua` derive proc macro to cover more cases
Diffstat (limited to 'mlua_derive/src')
-rw-r--r-- | mlua_derive/src/from_lua.rs | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/mlua_derive/src/from_lua.rs b/mlua_derive/src/from_lua.rs index 9e311e4..3d4e4ed 100644 --- a/mlua_derive/src/from_lua.rs +++ b/mlua_derive/src/from_lua.rs @@ -7,16 +7,17 @@ pub fn from_lua(input: TokenStream) -> TokenStream { ident, generics, .. } = parse_macro_input!(input as DeriveInput); + let ident_str = ident.to_string(); + let (impl_generics, ty_generics, _) = generics.split_for_impl(); let where_clause = match &generics.where_clause { Some(where_clause) => quote! { #where_clause, Self: 'static + Clone }, None => quote! { where Self: 'static + Clone }, }; - let ident_str = ident.to_string(); quote! { - impl #generics ::mlua::FromLua<'_> for #ident #generics #where_clause { + impl #impl_generics ::mlua::FromLua<'_> for #ident #ty_generics #where_clause { #[inline] - fn from_lua(value: ::mlua::Value<'_>, lua: &'_ ::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 { |