Skip to content

Commit bbe77da

Browse files
committed
simple register array iterator
1 parent 1dd3016 commit bbe77da

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/generate/peripheral/accessor.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use proc_macro2::{Ident, TokenStream};
1+
use proc_macro2::{Ident, TokenStream, Span};
22
use quote::{quote, ToTokens};
33

44
#[derive(Clone, Debug)]
@@ -138,12 +138,19 @@ pub struct ArrayAccessor {
138138
impl ToTokens for ArrayAccessor {
139139
fn to_tokens(&self, tokens: &mut TokenStream) {
140140
let Self { doc, name, ty, .. } = self;
141+
let name_iter = Ident::new(&format!("{name}_iter"), Span::call_site());
141142
quote! {
142143
#[doc = #doc]
143144
#[inline(always)]
144145
pub const fn #name(&self, n: usize) -> &#ty {
145146
&self.#name[n]
146147
}
148+
#[doc = "Iterator for array of:"]
149+
#[doc = #doc]
150+
#[inline(always)]
151+
pub fn #name_iter(&self) -> impl Iterator<Item=&#ty> {
152+
self.#name.iter()
153+
}
147154
}
148155
.to_tokens(tokens);
149156
}

0 commit comments

Comments
 (0)