@@ -51,8 +51,13 @@ pub use crate::jni_type_binding::TypeBinding;
5151/// Strategy for converting a JNI parameter into a Rust value.
5252#[ derive( Clone ) ]
5353pub enum ArgDecode {
54- /// `let <name> = <path>(&mut env, &<input>)?;`
54+ /// `let <name> = <path>(&mut env, &<input>)?;` — for decoders that need
55+ /// mutable access to the JNI environment (e.g. `JNIEnv::get_string`).
5556 EnvRefMut ( syn:: Path ) ,
57+ /// `let <name> = <path>(&env, &<input>)?;` — for decoders that only
58+ /// need shared access to the JNI environment (e.g. byte-array readers
59+ /// whose `JNIEnv` methods take `&self`).
60+ EnvRef ( syn:: Path ) ,
5661 /// `let <name> = <path>(<input>)?;` — pure conversion (e.g. enum decoders).
5762 Pure ( syn:: Path ) ,
5863 /// `let <name> = <expr>;` — inline transformation built from the input
@@ -80,6 +85,13 @@ impl ArgDecode {
8085 syn:: parse_str ( path. as_ref ( ) ) . expect ( "invalid ArgDecode::env_ref_mut path" ) ,
8186 )
8287 }
88+
89+ /// `ArgDecode::EnvRef` from a path string.
90+ pub fn env_ref ( path : impl AsRef < str > ) -> Self {
91+ ArgDecode :: EnvRef (
92+ syn:: parse_str ( path. as_ref ( ) ) . expect ( "invalid ArgDecode::env_ref path" ) ,
93+ )
94+ }
8395}
8496
8597impl ReturnEncode {
@@ -1185,6 +1197,9 @@ impl JniMethodsConverter {
11851197 ArgDecode :: EnvRefMut ( path) => {
11861198 prelude. push ( quote ! { let #name = #path( & mut env, & #pat) ?; } ) ;
11871199 }
1200+ ArgDecode :: EnvRef ( path) => {
1201+ prelude. push ( quote ! { let #name = #path( & env, & #pat) ?; } ) ;
1202+ }
11881203 ArgDecode :: Pure ( path) => {
11891204 prelude. push ( quote ! { let #name = #path( #pat) ?; } ) ;
11901205 }
@@ -1226,6 +1241,7 @@ impl JniMethodsConverter {
12261241 fn decode_expr ( & self , decode : & ArgDecode , input : & syn:: Ident ) -> TokenStream {
12271242 match decode {
12281243 ArgDecode :: EnvRefMut ( path) => quote ! { #path( & mut env, & #input) ? } ,
1244+ ArgDecode :: EnvRef ( path) => quote ! { #path( & env, & #input) ? } ,
12291245 ArgDecode :: Pure ( path) => quote ! { #path( #input) ? } ,
12301246 ArgDecode :: Inline ( f) => f. call ( input) ,
12311247 ArgDecode :: OwnedRef => {
0 commit comments