@@ -20,8 +20,8 @@ pub fn render(
2020 all_peripherals : & [ Peripheral ] ,
2121 defaults : & RegisterProperties ,
2222 nightly : bool ,
23- ) -> Result < Vec < TokenStream > > {
24- let mut out = vec ! [ ] ;
23+ ) -> Result < TokenStream > {
24+ let mut out = TokenStream :: new ( ) ;
2525
2626 let p_derivedfrom = p_original. derived_from . as_ref ( ) . and_then ( |s| {
2727 all_peripherals. iter ( ) . find ( |x| x. name == * s)
@@ -50,7 +50,7 @@ pub fn render(
5050 } ;
5151
5252 // Insert the peripheral structure
53- out. push ( quote ! {
53+ out. extend ( quote ! {
5454 #[ doc = #description]
5555 pub struct #name_pc { _marker: PhantomData <* const ( ) > }
5656
@@ -137,19 +137,18 @@ pub fn render(
137137 // No `struct RegisterBlock` can be generated
138138 if registers. is_empty ( ) && clusters. is_empty ( ) {
139139 // Drop the definition of the peripheral
140- out. pop ( ) ;
141- return Ok ( out) ;
140+ return Ok ( TokenStream :: new ( ) ) ;
142141 }
143142
144143 let defaults = p. default_register_properties . derive_from ( defaults) ;
145144
146145 // Push any register or cluster blocks into the output
147- let mut mod_items = vec ! [ ] ;
148- mod_items. push ( register_or_cluster_block ( ercs, & defaults, None , nightly) ?) ;
146+ let mut mod_items = TokenStream :: new ( ) ;
147+ mod_items. extend ( register_or_cluster_block ( ercs, & defaults, None , nightly) ?) ;
149148
150149 // Push all cluster related information into the peripheral module
151150 for c in & clusters {
152- mod_items. push ( cluster_block ( c, & defaults, p, all_peripherals, nightly) ?) ;
151+ mod_items. extend ( cluster_block ( c, & defaults, p, all_peripherals, nightly) ?) ;
153152 }
154153
155154 // Push all regsiter realted information into the peripheral module
@@ -169,18 +168,18 @@ pub fn render(
169168 let open = Punct :: new ( '{' , Spacing :: Alone ) ;
170169 let close = Punct :: new ( '}' , Spacing :: Alone ) ;
171170
172- out. push ( quote ! {
171+ out. extend ( quote ! {
173172 #[ doc = #description]
174173 pub mod #name_sc #open
175174 } ) ;
176175
177176 for item in mod_items {
178- out. push ( quote ! {
177+ out. extend ( quote ! {
179178 #item
180179 } ) ;
181180 }
182181
183- out. push ( quote ! {
182+ out. extend ( quote ! {
184183 #close
185184 } ) ;
186185
@@ -710,7 +709,7 @@ fn cluster_block(
710709 all_peripherals : & [ Peripheral ] ,
711710 nightly : bool ,
712711) -> Result < TokenStream > {
713- let mut mod_items: Vec < TokenStream > = vec ! [ ] ;
712+ let mut mod_items = TokenStream :: new ( ) ;
714713
715714 // name_sc needs to take into account array type.
716715 let description = util:: escape_brackets ( util:: respace ( & c. description ) . as_ref ( ) ) ;
@@ -743,7 +742,7 @@ fn cluster_block(
743742 // Generate the sub-cluster blocks.
744743 let clusters = util:: only_clusters ( & c. children ) ;
745744 for c in & clusters {
746- mod_items. push ( cluster_block ( c, & defaults, p, all_peripherals, nightly) ?) ;
745+ mod_items. extend ( cluster_block ( c, & defaults, p, all_peripherals, nightly) ?) ;
747746 }
748747
749748 Ok ( quote ! {
@@ -752,7 +751,7 @@ fn cluster_block(
752751 ///Register block
753752 #[ doc = #description]
754753 pub mod #name_sc {
755- #( # mod_items) *
754+ #mod_items
756755 }
757756 } )
758757}
0 commit comments