File tree Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Original file line number Diff line number Diff line change 1
- use proc_macro2:: { Ident , TokenStream , Span } ;
1
+ use proc_macro2:: { Ident , Span , TokenStream } ;
2
2
use quote:: { quote, ToTokens } ;
3
3
4
4
#[ derive( Clone , Debug ) ]
@@ -176,13 +176,21 @@ impl ToTokens for RawArrayAccessor {
176
176
dim,
177
177
increment,
178
178
} = self ;
179
+ let name_iter = Ident :: new ( & format ! ( "{name}_iter" ) , Span :: call_site ( ) ) ;
180
+ let cast = quote ! { unsafe { & * ( self as * const Self ) . cast:: <u8 >( ) . add( #offset) . add( #increment * n) . cast( ) } } ;
179
181
quote ! {
180
182
#[ doc = #doc]
181
183
#[ inline( always) ]
182
184
pub const fn #name( & self , n: usize ) -> & #ty {
183
185
#[ allow( clippy:: no_effect) ]
184
186
[ ( ) ; #dim] [ n] ;
185
- unsafe { & * ( self as * const Self ) . cast:: <u8 >( ) . add( #offset) . add( #increment * n) . cast( ) }
187
+ #cast
188
+ }
189
+ #[ doc = "Iterator for array of:" ]
190
+ #[ doc = #doc]
191
+ #[ inline( always) ]
192
+ pub fn #name_iter( & self ) -> impl Iterator <Item =& #ty> {
193
+ ( 0 ..#dim) . map( |n| #cast)
186
194
}
187
195
}
188
196
. to_tokens ( tokens) ;
You can’t perform that action at this time.
0 commit comments