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 } ;
22use quote:: { quote, ToTokens } ;
33
44#[ derive( Clone , Debug ) ]
@@ -176,13 +176,21 @@ impl ToTokens for RawArrayAccessor {
176176 dim,
177177 increment,
178178 } = 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( ) } } ;
179181 quote ! {
180182 #[ doc = #doc]
181183 #[ inline( always) ]
182184 pub const fn #name( & self , n: usize ) -> & #ty {
183185 #[ allow( clippy:: no_effect) ]
184186 [ ( ) ; #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)
186194 }
187195 }
188196 . to_tokens ( tokens) ;
You can’t perform that action at this time.
0 commit comments