@@ -48,44 +48,30 @@ pub struct TableHeadEvent {
4848 pub mouse_event : MouseEvent ,
4949}
5050
51- macro_rules! impl_default_arc_fn {
52- (
53- $( #[ $meta: meta] ) *
54- $name: ident<$( $ty: ident) ,* >( $( $arg_name: ident: $arg_ty: ty) ,* )
55- $( -> $ret_ty: ty) ?
56- $( { default $default_return: expr } ) ?
57- ) => {
58- $( #[ $meta] ) *
59- #[ derive( Clone ) ]
60- pub struct $name<$( $ty) ,* >( Arc <dyn Fn ( $( $arg_ty) ,* ) $( -> $ret_ty) ? + Send + Sync >) ;
51+ /// New type wrapper of a closure that takes a parameter `T`. This allows the event handler props
52+ /// to be optional while being able to take a simple closure.
53+ #[ derive( Clone ) ]
54+ pub struct EventHandler < T > ( Arc < dyn Fn ( T ) + Send + Sync > ) ;
6155
62- impl <$( $ty) ,* > Default for $name<$( $ty) ,* > {
63- fn default ( ) -> Self {
64- #[ allow( unused_variables) ]
65- Self ( Arc :: new( |$( $arg_name: $arg_ty) ,* | {
66- $( $default_return) ?
67- } ) )
68- }
69- }
70-
71- impl <F , $( $ty) ,* > From <F > for $name<$( $ty) ,* >
72- where F : Fn ( $( $arg_ty) ,* ) $( -> $ret_ty) ? + Send + Sync + ' static
73- {
74- fn from( f: F ) -> Self { Self ( Arc :: new( f) ) }
75- }
76-
77- impl <$( $ty) ,* > $name<$( $ty) ,* > {
78- pub fn run( & self , $( $arg_name: $arg_ty) ,* ) $( -> $ret_ty) ? {
79- ( self . 0 ) ( $( $arg_name) ,* )
80- }
81- }
56+ impl < T > Default for EventHandler < T > {
57+ fn default ( ) -> Self {
58+ #[ allow( unused_variables) ]
59+ Self ( Arc :: new ( |event : T | { } ) )
8260 }
8361}
8462
85- impl_default_arc_fn ! (
86- /// New type wrapper of a closure that takes a parameter `T`. This allows the event handler props
87- /// to be optional while being able to take a simple closure.
88- EventHandler <T >( event: T )
89- ) ;
63+ impl < F , T > From < F > for EventHandler < T >
64+ where
65+ F : Fn ( T ) + Send + Sync + ' static ,
66+ {
67+ fn from ( f : F ) -> Self {
68+ Self ( Arc :: new ( f) )
69+ }
70+ }
9071
91- pub ( crate ) use impl_default_arc_fn;
72+ impl < T > EventHandler < T > {
73+ #[ inline]
74+ pub fn run ( & self , event : T ) {
75+ ( self . 0 ) ( event)
76+ }
77+ }
0 commit comments