@@ -20,8 +20,8 @@ pub fn render(
20
20
all_peripherals : & [ Peripheral ] ,
21
21
defaults : & RegisterProperties ,
22
22
nightly : bool ,
23
- ) -> Result < Vec < TokenStream > > {
24
- let mut out = vec ! [ ] ;
23
+ ) -> Result < TokenStream > {
24
+ let mut out = TokenStream :: new ( ) ;
25
25
26
26
let p_derivedfrom = p_original. derived_from . as_ref ( ) . and_then ( |s| {
27
27
all_peripherals. iter ( ) . find ( |x| x. name == * s)
@@ -50,7 +50,7 @@ pub fn render(
50
50
} ;
51
51
52
52
// Insert the peripheral structure
53
- out. push ( quote ! {
53
+ out. extend ( quote ! {
54
54
#[ doc = #description]
55
55
pub struct #name_pc { _marker: PhantomData <* const ( ) > }
56
56
@@ -137,19 +137,18 @@ pub fn render(
137
137
// No `struct RegisterBlock` can be generated
138
138
if registers. is_empty ( ) && clusters. is_empty ( ) {
139
139
// Drop the definition of the peripheral
140
- out. pop ( ) ;
141
- return Ok ( out) ;
140
+ return Ok ( TokenStream :: new ( ) ) ;
142
141
}
143
142
144
143
let defaults = p. default_register_properties . derive_from ( defaults) ;
145
144
146
145
// 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) ?) ;
149
148
150
149
// Push all cluster related information into the peripheral module
151
150
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) ?) ;
153
152
}
154
153
155
154
// Push all regsiter realted information into the peripheral module
@@ -169,18 +168,18 @@ pub fn render(
169
168
let open = Punct :: new ( '{' , Spacing :: Alone ) ;
170
169
let close = Punct :: new ( '}' , Spacing :: Alone ) ;
171
170
172
- out. push ( quote ! {
171
+ out. extend ( quote ! {
173
172
#[ doc = #description]
174
173
pub mod #name_sc #open
175
174
} ) ;
176
175
177
176
for item in mod_items {
178
- out. push ( quote ! {
177
+ out. extend ( quote ! {
179
178
#item
180
179
} ) ;
181
180
}
182
181
183
- out. push ( quote ! {
182
+ out. extend ( quote ! {
184
183
#close
185
184
} ) ;
186
185
@@ -710,7 +709,7 @@ fn cluster_block(
710
709
all_peripherals : & [ Peripheral ] ,
711
710
nightly : bool ,
712
711
) -> Result < TokenStream > {
713
- let mut mod_items: Vec < TokenStream > = vec ! [ ] ;
712
+ let mut mod_items = TokenStream :: new ( ) ;
714
713
715
714
// name_sc needs to take into account array type.
716
715
let description = util:: escape_brackets ( util:: respace ( & c. description ) . as_ref ( ) ) ;
@@ -743,7 +742,7 @@ fn cluster_block(
743
742
// Generate the sub-cluster blocks.
744
743
let clusters = util:: only_clusters ( & c. children ) ;
745
744
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) ?) ;
747
746
}
748
747
749
748
Ok ( quote ! {
@@ -752,7 +751,7 @@ fn cluster_block(
752
751
///Register block
753
752
#[ doc = #description]
754
753
pub mod #name_sc {
755
- #( # mod_items) *
754
+ #mod_items
756
755
}
757
756
} )
758
757
}
0 commit comments