@@ -48,7 +48,7 @@ use crate::{ffi, Encode, EncodeArguments, Encoding, Message};
4848/// Types that can be used as the implementation of an Objective-C method.
4949pub trait MethodImplementation {
5050 /// The callee type of the method.
51- type Callee : Message + ?Sized ;
51+ type Callee : ?Sized ;
5252 /// The return type of the method.
5353 type Ret : Encode ;
5454 /// The argument types of the method.
@@ -75,13 +75,32 @@ macro_rules! method_decl_impl {
7575 }
7676 }
7777 ) ;
78+ ( @$s: ident, $r: ident, $f: ty, $( $t: ident) ,* ) => (
79+ impl <$r, $( $t) ,* > MethodImplementation for $f
80+ where
81+ $r: Encode ,
82+ $( $t: Encode , ) *
83+ {
84+ type Callee = $s;
85+ type Ret = $r;
86+ type Args = ( $( $t, ) * ) ;
87+
88+ fn imp( self ) -> Imp {
89+ unsafe { mem:: transmute( self ) }
90+ }
91+ }
92+ ) ;
7893 ( $( $t: ident) ,* ) => (
7994 method_decl_impl!( -T , R , extern "C" fn ( & T , Sel $( , $t) * ) -> R , $( $t) ,* ) ;
8095 method_decl_impl!( -T , R , extern "C" fn ( & mut T , Sel $( , $t) * ) -> R , $( $t) ,* ) ;
8196 method_decl_impl!( -T , R , unsafe extern "C" fn ( * const T , Sel $( , $t) * ) -> R , $( $t) ,* ) ;
8297 method_decl_impl!( -T , R , unsafe extern "C" fn ( * mut T , Sel $( , $t) * ) -> R , $( $t) ,* ) ;
8398 method_decl_impl!( -T , R , unsafe extern "C" fn ( & T , Sel $( , $t) * ) -> R , $( $t) ,* ) ;
8499 method_decl_impl!( -T , R , unsafe extern "C" fn ( & mut T , Sel $( , $t) * ) -> R , $( $t) ,* ) ;
100+
101+ method_decl_impl!( @Class , R , extern "C" fn ( & Class , Sel $( , $t) * ) -> R , $( $t) ,* ) ;
102+ method_decl_impl!( @Class , R , unsafe extern "C" fn ( * const Class , Sel $( , $t) * ) -> R , $( $t) ,* ) ;
103+ method_decl_impl!( @Class , R , unsafe extern "C" fn ( & Class , Sel $( , $t) * ) -> R , $( $t) ,* ) ;
85104 ) ;
86105}
87106
@@ -200,7 +219,7 @@ impl ClassBuilder {
200219 /// when the method is invoked from Objective-C.
201220 pub unsafe fn add_method < T , F > ( & mut self , sel : Sel , func : F )
202221 where
203- T : Message + ?Sized , // TODO: Disallow `Class`
222+ T : Message + ?Sized ,
204223 F : MethodImplementation < Callee = T > ,
205224 {
206225 let encs = F :: Args :: ENCODINGS ;
0 commit comments