@@ -93,10 +93,6 @@ pub(crate) struct KotlinConfig {
9393 /// FQN of a singleton referenced inside the generated `init { ... }` block
9494 /// to force native-library loading — `None` disables the `init`.
9595 init_load_fqn : Option < String > ,
96- /// FQN of the on-close callback type (typically
97- /// `io.zenoh.jni.callbacks.JNIOnCloseCallback`). Used for the synthetic
98- /// `<name>OnClose` parameter injected for every callback arg.
99- on_close_callback_fqn : String ,
10096 /// Per-source-type Kotlin names (FQN or bare) for struct-decoded args.
10197 struct_kotlin_types : HashMap < String , String > ,
10298 /// Per-element-type Kotlin names for callback args (e.g. `Sample` →
@@ -381,13 +377,6 @@ impl Builder {
381377 self
382378 }
383379
384- /// FQN of the Kotlin on-close callback type used for the synthetic
385- /// `<name>OnClose` parameter injected for each callback argument.
386- pub fn kotlin_on_close ( mut self , fqn : impl Into < String > ) -> Self {
387- self . kotlin . get_or_insert_with ( KotlinConfig :: default) . on_close_callback_fqn = fqn. into ( ) ;
388- self
389- }
390-
391380 pub fn build ( self ) -> JniConverter {
392381 JniConverter {
393382 cfg : self ,
@@ -408,7 +397,6 @@ impl Default for KotlinConfig {
408397 class_name : String :: new ( ) ,
409398 throws_class_fqn : None ,
410399 init_load_fqn : None ,
411- on_close_callback_fqn : String :: new ( ) ,
412400 struct_kotlin_types : HashMap :: new ( ) ,
413401 callback_kotlin_types : HashMap :: new ( ) ,
414402 return_kotlin_types : HashMap :: new ( ) ,
@@ -778,11 +766,9 @@ impl JniConverter {
778766 }
779767 }
780768 ArgKind :: Callback { decoder, element_type_name } => {
781- let on_close_ident = format_ident ! ( "{}_on_close" , name) ;
782769 jni_params. push ( quote ! { #name: jni:: objects:: JObject } ) ;
783- jni_params. push ( quote ! { #on_close_ident: jni:: objects:: JObject } ) ;
784770 prelude. push ( quote ! {
785- let #name = #decoder( & mut env, #name, #on_close_ident ) ?;
771+ let #name = #decoder( & mut env, #name) ?;
786772 } ) ;
787773 call_args. push ( quote ! { #name } ) ;
788774 if let Some ( kt) = kt_cfg {
@@ -792,17 +778,11 @@ impl JniConverter {
792778 element_type_name
793779 ) ) ;
794780 let cb_short = kotlin_register_fqn ( & cb_fqn, & mut local_kotlin_fqns) ;
795- let oc_short = kotlin_register_fqn ( & kt. on_close_callback_fqn , & mut local_kotlin_fqns) ;
796781 kotlin_params. push ( format ! (
797782 "{}: {}" ,
798783 kotlin_param_name( & name. to_string( ) , false ) ,
799784 cb_short
800785 ) ) ;
801- kotlin_params. push ( format ! (
802- "{}OnClose: {}" ,
803- kotlin_param_name( & name. to_string( ) , false ) ,
804- oc_short
805- ) ) ;
806786 }
807787 }
808788 ArgKind :: OptionString => {
@@ -1209,7 +1189,7 @@ impl JniConverter {
12091189 }
12101190 }
12111191 syn:: Type :: ImplTrait ( it) => {
1212- if let Some ( elem) = extract_fn_single_arg_type_name ( & it. bounds ) {
1192+ if let Some ( elem) = extract_fn_arg_type_name ( & it. bounds ) {
12131193 if let Some ( decoder) = self . cfg . callback_decoders . get ( & elem) {
12141194 return ArgKind :: Callback {
12151195 decoder : decoder. clone ( ) ,
@@ -1308,8 +1288,9 @@ enum ArgKind {
13081288 decoder : syn:: Path ,
13091289 type_name : String ,
13101290 } ,
1311- /// `impl Fn(T) + Send + Sync + 'static` → `(JObject callback, JObject on_close)`
1312- /// pair decoded via a callback decoder registered for `T`.
1291+ /// `impl Fn(T) + Send + Sync + 'static` → single `JObject` decoded via the
1292+ /// callback decoder registered for `T`. Zero-arg `impl Fn() + Send + Sync`
1293+ /// callbacks are looked up under the key `"()"`.
13131294 Callback {
13141295 decoder : syn:: Path ,
13151296 element_type_name : String ,
@@ -1335,9 +1316,11 @@ fn type_last_segment(ty: &syn::Type) -> Option<String> {
13351316 tp. path . segments . last ( ) . map ( |s| s. ident . to_string ( ) )
13361317}
13371318
1338- /// Look through the trait bounds of an `impl Fn(T) + ...` for a `Fn`-family
1339- /// trait and return the last-segment name of its single argument type `T`.
1340- fn extract_fn_single_arg_type_name (
1319+ /// Look through the trait bounds of an `impl Fn(...) + ...` for a `Fn`-family
1320+ /// trait and return the lookup key for its argument type:
1321+ /// - `impl Fn(T)` → `Some("T")`
1322+ /// - `impl Fn()` → `Some("()")` (zero-arg callbacks, e.g. on-close handlers)
1323+ fn extract_fn_arg_type_name (
13411324 bounds : & syn:: punctuated:: Punctuated < syn:: TypeParamBound , syn:: Token ![ +] > ,
13421325) -> Option < String > {
13431326 for bound in bounds {
@@ -1347,8 +1330,10 @@ fn extract_fn_single_arg_type_name(
13471330 continue ;
13481331 }
13491332 let syn:: PathArguments :: Parenthesized ( p) = & seg. arguments else { continue } ;
1350- let first = p. inputs . first ( ) ?;
1351- return type_last_segment ( first) ;
1333+ return match p. inputs . first ( ) {
1334+ Some ( first) => type_last_segment ( first) ,
1335+ None => Some ( "()" . to_string ( ) ) ,
1336+ } ;
13521337 }
13531338 None
13541339}
0 commit comments