@@ -34,48 +34,9 @@ pub fn parser(mut input: ItemTrait) -> Result<TokenStream> {
3434 let name = attr. rename . rename ( ident. to_string ( ) , RenameRule :: Pascal ) ;
3535 input. attrs . clean_php ( ) ;
3636
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 ( ) ?;
6438
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 ( ) ?;
7940
8041 let implements = attr. extends ;
8142
@@ -84,10 +45,6 @@ pub fn parser(mut input: ItemTrait) -> Result<TokenStream> {
8445
8546 pub struct #interface_name;
8647
87- impl #interface_name {
88- #( pub #impl_const) *
89- }
90-
9148 impl :: ext_php_rs:: class:: RegisteredClass for #interface_name {
9249 const CLASS_NAME : & ' static str = #name;
9350
@@ -153,7 +110,7 @@ pub fn parser(mut input: ItemTrait) -> Result<TokenStream> {
153110 }
154111
155112 fn get_constants( self ) -> & ' static [ ( & ' static str , & ' static dyn :: ext_php_rs:: convert:: IntoZvalDyn , & ' static [ & ' static str ] ) ] {
156- & [ # ( #constants ) , * ]
113+ & [ ]
157114 }
158115 }
159116
@@ -242,6 +199,33 @@ trait Parse<'a, T> {
242199 fn parse ( & ' a mut self ) -> Result < T > ;
243200}
244201
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+
245229impl < ' a > Parse < ' a , Constant < ' a > > for TraitItemConst {
246230 fn parse ( & ' a mut self ) -> Result < Constant < ' a > > {
247231 let attr = PhpConstAttribute :: from_attributes ( & self . attrs ) ?;
0 commit comments