1- #![ recursion_limit = "128" ]
21#![ feature( proc_macro, proc_macro_lib) ]
32
43extern crate proc_macro;
5- extern crate syn;
64#[ macro_use]
75extern crate quote;
6+ extern crate syn;
87
98use proc_macro:: TokenStream ;
9+ use quote:: { Tokens , ToTokens } ;
1010
1111#[ proc_macro_derive( INSObject ) ]
1212pub fn impl_object ( input : TokenStream ) -> TokenStream {
@@ -21,9 +21,12 @@ pub fn impl_object(input: TokenStream) -> TokenStream {
2121 let link_name = format ! ( "OBJC_CLASS_$_{}" , name) ;
2222 let ( impl_generics, ty_generics, where_clause) = ast. generics . split_for_impl ( ) ;
2323
24- let gen = quote ! {
24+ let mut gen = Tokens :: new ( ) ;
25+ quote ! (
2526 unsafe impl #impl_generics :: objc:: Message for #name #ty_generics #where_clause { }
27+ ) . to_tokens ( & mut gen) ;
2628
29+ quote ! (
2730 impl #impl_generics :: objc_foundation:: INSObject for #name #ty_generics #where_clause {
2831 fn class( ) -> & ' static :: objc:: runtime:: Class {
2932 extern {
@@ -35,28 +38,34 @@ pub fn impl_object(input: TokenStream) -> TokenStream {
3538 }
3639 }
3740 }
41+ ) . to_tokens ( & mut gen) ;
3842
43+ quote ! (
3944 impl #impl_generics :: std:: cmp:: PartialEq for #name #ty_generics #where_clause {
4045 fn eq( & self , other: & Self ) -> bool {
4146 use :: objc_foundation:: INSObject ;
4247 self . is_equal( other)
4348 }
4449 }
50+ ) . to_tokens ( & mut gen) ;
4551
52+ quote ! (
4653 impl #impl_generics :: std:: hash:: Hash for #name #ty_generics #where_clause {
4754 fn hash<H >( & self , state: & mut H ) where H : :: std:: hash:: Hasher {
4855 use :: objc_foundation:: INSObject ;
4956 self . hash_code( ) . hash( state) ;
5057 }
5158 }
59+ ) . to_tokens ( & mut gen) ;
5260
61+ quote ! (
5362 impl #impl_generics :: std:: fmt:: Debug for #name #ty_generics #where_clause {
5463 fn fmt( & self , f: & mut :: std:: fmt:: Formatter ) -> :: std:: fmt:: Result {
5564 use :: objc_foundation:: { INSObject , INSString } ;
5665 :: std:: fmt:: Debug :: fmt( self . description( ) . as_str( ) , f)
5766 }
5867 }
59- } ;
68+ ) . to_tokens ( & mut gen ) ;
6069
6170 // Return the generated impl
6271 gen. parse ( ) . unwrap ( )
0 commit comments