diff --git a/deku-derive/src/macros/deku_read.rs b/deku-derive/src/macros/deku_read.rs index 5d76c3f2..d5225baa 100644 --- a/deku-derive/src/macros/deku_read.rs +++ b/deku-derive/src/macros/deku_read.rs @@ -403,8 +403,12 @@ fn emit_enum(input: &DekuData) -> Result { // Implement `DekuEnumExt` if let Some(deku_id_type) = deku_id_type { - tokens.extend(quote! { - impl #imp DekuEnumExt<#lifetime, (#deku_id_type)> for #ident #wher { + if !imp.to_token_stream().is_empty() { + // Generics (#imp) are not supported, as our __deku + // would need to be appended to #imp + } else { + tokens.extend(quote! { + impl<'__deku> #imp ::#crate_::DekuEnumExt<#lifetime, (#deku_id_type)> for #ident #wher { fn deku_id(&self) -> core::result::Result<(#deku_id_type), DekuError> { match self { #(#deku_ids ,)* @@ -413,6 +417,7 @@ fn emit_enum(input: &DekuData) -> Result { } } }); + } } // println!("{}", tokens.to_string()); diff --git a/deku-derive/src/macros/mod.rs b/deku-derive/src/macros/mod.rs index 2fa865c3..fa5bf37b 100644 --- a/deku-derive/src/macros/mod.rs +++ b/deku-derive/src/macros/mod.rs @@ -4,6 +4,7 @@ use syn::parse::Parser; use syn::punctuated::Punctuated; use syn::spanned::Spanned; use syn::token::Comma; +use syn::Lifetime; use crate::Num; @@ -211,6 +212,10 @@ fn gen_type_from_ctx_id( if let syn::FnArg::Typed(pat_type) = arg { if let syn::Pat::Ident(ident) = &*pat_type.pat { if id == ident.ident { + let mut pat_type = pat_type.clone(); + if let syn::Type::Reference(r) = pat_type.ty.as_mut() { + r.lifetime = Some(Lifetime::new("'__deku", Span::call_site())); + } let ty = &pat_type.ty; t = Some(quote! {#ty}); } diff --git a/src/lib.rs b/src/lib.rs index 64d36de5..54f463ed 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -452,7 +452,7 @@ pub trait DekuUpdate { } /// "Extended Enum" trait: obtain additional enum information -pub trait DekuEnumExt<'a, T> { +pub trait DekuEnumExt<'__deku, T> { /// Obtain `id` of a given enum variant fn deku_id(&self) -> Result; }