1
1
// Take a look at the license at the top of the repository in the LICENSE file.
2
2
3
- use std:: { fmt, num:: NonZeroU32 , ptr, sync:: Mutex } ;
3
+ use std:: { fmt, num:: NonZeroU32 , ops :: ControlFlow , ptr, sync:: Mutex } ;
4
4
5
5
use crate :: {
6
6
ffi, gobject_ffi, prelude:: * , translate:: * , utils:: is_canonical_pspec_name, Closure ,
@@ -18,7 +18,12 @@ pub struct SignalBuilder {
18
18
return_type : SignalType ,
19
19
class_handler : Option < Box < dyn Fn ( & [ Value ] ) -> Option < Value > + Send + Sync + ' static > > ,
20
20
accumulator : Option <
21
- Box < dyn Fn ( & SignalInvocationHint , & mut Value , & Value ) -> bool + Send + Sync + ' static > ,
21
+ Box <
22
+ dyn Fn ( & SignalInvocationHint , Value , & Value ) -> ControlFlow < Value , Value >
23
+ + Send
24
+ + Sync
25
+ + ' static ,
26
+ > ,
22
27
> ,
23
28
}
24
29
@@ -352,7 +357,12 @@ enum SignalRegistration {
352
357
Unregistered {
353
358
class_handler : Option < Box < dyn Fn ( & [ Value ] ) -> Option < Value > + Send + Sync + ' static > > ,
354
359
accumulator : Option <
355
- Box < dyn Fn ( & SignalInvocationHint , & mut Value , & Value ) -> bool + Send + Sync + ' static > ,
360
+ Box <
361
+ dyn Fn ( & SignalInvocationHint , Value , & Value ) -> ControlFlow < Value , Value >
362
+ + Send
363
+ + Sync
364
+ + ' static ,
365
+ > ,
356
366
> ,
357
367
} ,
358
368
Registered {
@@ -480,7 +490,10 @@ impl SignalBuilder {
480
490
/// This is called if multiple signal handlers are connected to the signal for accumulating the
481
491
/// return values into a single value.
482
492
pub fn accumulator <
483
- F : Fn ( & SignalInvocationHint , & mut Value , & Value ) -> bool + Send + Sync + ' static ,
493
+ F : Fn ( & SignalInvocationHint , Value , & Value ) -> ControlFlow < Value , Value >
494
+ + Send
495
+ + Sync
496
+ + ' static ,
484
497
> (
485
498
mut self ,
486
499
func : F ,
@@ -633,7 +646,7 @@ impl Signal {
633
646
let accumulator = & * ( data as * const (
634
647
SignalType ,
635
648
Box <
636
- dyn Fn ( & SignalInvocationHint , & mut Value , & Value ) -> bool
649
+ dyn Fn ( & SignalInvocationHint , Value , & Value ) -> ControlFlow < Value , Value >
637
650
+ Send
638
651
+ Sync
639
652
+ ' static ,
@@ -651,8 +664,23 @@ impl Signal {
651
664
handler_return. type_( )
652
665
) ;
653
666
654
- let res = ( accumulator. 1 ) ( & SignalInvocationHint ( * ihint) , return_accu, handler_return)
655
- . into_glib ( ) ;
667
+ let control_flow = ( accumulator. 1 ) (
668
+ & SignalInvocationHint ( * ihint) ,
669
+ std:: mem:: replace ( return_accu, Value :: uninitialized ( ) ) ,
670
+ handler_return,
671
+ ) ;
672
+
673
+ let res = match control_flow {
674
+ ControlFlow :: Continue ( val) => {
675
+ * return_accu = val;
676
+ true . into_glib ( )
677
+ }
678
+
679
+ ControlFlow :: Break ( val) => {
680
+ * return_accu = val;
681
+ false . into_glib ( )
682
+ }
683
+ } ;
656
684
657
685
assert ! (
658
686
return_accu. type_( ) . is_a( return_type. into( ) ) ,
0 commit comments