fix: handle mut modifier in arguments

This commit is contained in:
əlemi 2024-09-21 18:08:19 +02:00
parent f00b8dc398
commit d3da081886
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -117,7 +117,7 @@ fn generate_jni_wrapper(attrs: TokenStream, input: TokenStream) -> Result<TokenS
return Err(syn::Error::new(Span::call_site(), "#[jni] macro doesn't work on methods")); return Err(syn::Error::new(Span::call_site(), "#[jni] macro doesn't work on methods"));
}; };
incoming.append_all(quote::quote!( #ty , )); incoming.append_all(quote::quote!( #ty , ));
let pat = ty.pat; let pat = unpack_pat(*ty.pat)?;
forwarding.append_all(quote::quote!( #pat , )); forwarding.append_all(quote::quote!( #pat , ));
} }
@ -195,3 +195,16 @@ enum WhatNext {
Class, Class,
Exception, Exception,
} }
fn unpack_pat(pat: syn::Pat) -> Result<TokenStream, syn::Error> {
match pat {
syn::Pat::Ident(i) => {
let ident = i.ident;
Ok(quote::quote!( #ident ,))
},
syn::Pat::Reference(r) => {
unpack_pat(*r.pat)
},
_ => Err(syn::Error::new(Span::call_site(), "unsupported argument type")),
}
}