1
- #![ recursion_limit = "128" ]
2
1
#![ feature( proc_macro, proc_macro_lib) ]
3
2
4
3
extern crate proc_macro;
5
- extern crate syn;
6
4
#[ macro_use]
7
5
extern crate quote;
6
+ extern crate syn;
8
7
9
8
use proc_macro:: TokenStream ;
9
+ use quote:: { Tokens , ToTokens } ;
10
10
11
11
#[ proc_macro_derive( INSObject ) ]
12
12
pub fn impl_object ( input : TokenStream ) -> TokenStream {
@@ -21,9 +21,12 @@ pub fn impl_object(input: TokenStream) -> TokenStream {
21
21
let link_name = format ! ( "OBJC_CLASS_$_{}" , name) ;
22
22
let ( impl_generics, ty_generics, where_clause) = ast. generics . split_for_impl ( ) ;
23
23
24
- let gen = quote ! {
24
+ let mut gen = Tokens :: new ( ) ;
25
+ quote ! (
25
26
unsafe impl #impl_generics :: objc:: Message for #name #ty_generics #where_clause { }
27
+ ) . to_tokens ( & mut gen) ;
26
28
29
+ quote ! (
27
30
impl #impl_generics :: objc_foundation:: INSObject for #name #ty_generics #where_clause {
28
31
fn class( ) -> & ' static :: objc:: runtime:: Class {
29
32
extern {
@@ -35,28 +38,34 @@ pub fn impl_object(input: TokenStream) -> TokenStream {
35
38
}
36
39
}
37
40
}
41
+ ) . to_tokens ( & mut gen) ;
38
42
43
+ quote ! (
39
44
impl #impl_generics :: std:: cmp:: PartialEq for #name #ty_generics #where_clause {
40
45
fn eq( & self , other: & Self ) -> bool {
41
46
use :: objc_foundation:: INSObject ;
42
47
self . is_equal( other)
43
48
}
44
49
}
50
+ ) . to_tokens ( & mut gen) ;
45
51
52
+ quote ! (
46
53
impl #impl_generics :: std:: hash:: Hash for #name #ty_generics #where_clause {
47
54
fn hash<H >( & self , state: & mut H ) where H : :: std:: hash:: Hasher {
48
55
use :: objc_foundation:: INSObject ;
49
56
self . hash_code( ) . hash( state) ;
50
57
}
51
58
}
59
+ ) . to_tokens ( & mut gen) ;
52
60
61
+ quote ! (
53
62
impl #impl_generics :: std:: fmt:: Debug for #name #ty_generics #where_clause {
54
63
fn fmt( & self , f: & mut :: std:: fmt:: Formatter ) -> :: std:: fmt:: Result {
55
64
use :: objc_foundation:: { INSObject , INSString } ;
56
65
:: std:: fmt:: Debug :: fmt( self . description( ) . as_str( ) , f)
57
66
}
58
67
}
59
- } ;
68
+ ) . to_tokens ( & mut gen ) ;
60
69
61
70
// Return the generated impl
62
71
gen. parse ( ) . unwrap ( )
0 commit comments