@@ -34,48 +34,9 @@ pub fn parser(mut input: ItemTrait) -> Result<TokenStream> {
34
34
let name = attr. rename . rename ( ident. to_string ( ) , RenameRule :: Pascal ) ;
35
35
input. attrs . clean_php ( ) ;
36
36
37
- let methods: Vec < FnBuilder > = input
38
- . items
39
- . iter_mut ( )
40
- . flat_map ( |item : & mut TraitItem | match item {
41
- TraitItem :: Fn ( f) => Some ( f) ,
42
- _ => None ,
43
- } )
44
- . flat_map ( |f| f. parse ( ) )
45
- . collect ( ) ;
46
-
47
- let constants: Vec < _ > = input
48
- . items
49
- . iter_mut ( )
50
- . flat_map ( |item : & mut TraitItem | match item {
51
- TraitItem :: Const ( c) => Some ( c) ,
52
- _ => None ,
53
- } )
54
- . flat_map ( |c| c. parse ( ) )
55
- . map ( |c| {
56
- let name = & c. name ;
57
- let ident = c. ident ;
58
- let docs = & c. docs ;
59
- quote ! {
60
- ( #name, & #path:: #ident, & [ #( #docs) , * ] )
61
- }
62
- } )
63
- . collect ( ) ;
37
+ let methods: Vec < FnBuilder > = input. parse ( ) ?;
64
38
65
- let impl_const: Vec < & TraitItemConst > = input
66
- . items
67
- . iter ( )
68
- . flat_map ( |item| match item {
69
- TraitItem :: Const ( c) => Some ( c) ,
70
- _ => None ,
71
- } )
72
- . flat_map ( |c| {
73
- if c. default . is_none ( ) {
74
- bail ! ( "Interface const cannot be empty" ) ;
75
- }
76
- Ok ( c)
77
- } )
78
- . collect ( ) ;
39
+ let constants: Vec < Constant > = input. parse ( ) ?;
79
40
80
41
let implements = attr. extends ;
81
42
@@ -84,10 +45,6 @@ pub fn parser(mut input: ItemTrait) -> Result<TokenStream> {
84
45
85
46
pub struct #interface_name;
86
47
87
- impl #interface_name {
88
- #( pub #impl_const) *
89
- }
90
-
91
48
impl :: ext_php_rs:: class:: RegisteredClass for #interface_name {
92
49
const CLASS_NAME : & ' static str = #name;
93
50
@@ -153,7 +110,7 @@ pub fn parser(mut input: ItemTrait) -> Result<TokenStream> {
153
110
}
154
111
155
112
fn get_constants( self ) -> & ' static [ ( & ' static str , & ' static dyn :: ext_php_rs:: convert:: IntoZvalDyn , & ' static [ & ' static str ] ) ] {
156
- & [ # ( #constants ) , * ]
113
+ & [ ]
157
114
}
158
115
}
159
116
@@ -242,6 +199,33 @@ trait Parse<'a, T> {
242
199
fn parse ( & ' a mut self ) -> Result < T > ;
243
200
}
244
201
202
+ impl < ' a > Parse < ' a , Vec < FnBuilder > > for ItemTrait {
203
+ fn parse ( & ' a mut self ) -> Result < Vec < FnBuilder > > {
204
+ Ok ( self
205
+ . items
206
+ . iter_mut ( )
207
+ . filter_map ( |item : & mut TraitItem | match item {
208
+ TraitItem :: Fn ( f) => Some ( f) ,
209
+ _ => None ,
210
+ } )
211
+ . flat_map ( Parse :: parse)
212
+ . collect ( ) )
213
+ }
214
+ }
215
+
216
+ impl < ' a > Parse < ' a , Vec < Constant < ' a > > > for ItemTrait {
217
+ fn parse ( & ' a mut self ) -> Result < Vec < Constant < ' a > > > {
218
+ Ok ( self . items
219
+ . iter_mut ( )
220
+ . filter_map ( |item : & mut TraitItem | match item {
221
+ TraitItem :: Const ( c) => Some ( c) ,
222
+ _ => None ,
223
+ } )
224
+ . flat_map ( Parse :: parse)
225
+ . collect ( ) )
226
+ }
227
+ }
228
+
245
229
impl < ' a > Parse < ' a , Constant < ' a > > for TraitItemConst {
246
230
fn parse ( & ' a mut self ) -> Result < Constant < ' a > > {
247
231
let attr = PhpConstAttribute :: from_attributes ( & self . attrs ) ?;
0 commit comments