File tree Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -39,6 +39,9 @@ pub fn derive(input: &Input) -> TokenStream {
3939 . map ( |field| format ! ( "A slice of `{0}` from a [`{1}`](struct.{1}.html)" , field, vec_name) )
4040 . collect :: < Vec < _ > > ( ) ;
4141
42+ let field_attrs = input. field_attrs . iter ( )
43+ . map ( |attr| & attr. slice ) . collect :: < Vec < _ > > ( ) ;
44+
4245 let mut generated = quote ! {
4346 /// A slice of
4447 #[ doc = #doc_url]
@@ -51,6 +54,7 @@ pub fn derive(input: &Input) -> TokenStream {
5154 #visibility struct #slice_name<' a> {
5255 #(
5356 #[ doc = #fields_doc]
57+ #( #[ #field_attrs] ) *
5458 pub #fields_names: & ' a [ #fields_types] ,
5559 ) *
5660 }
@@ -272,6 +276,9 @@ pub fn derive_mut(input: &Input) -> TokenStream {
272276 . map ( |field| format ! ( "A mutable slice of `{0}` from a [`{1}`](struct.{1}.html)" , field, vec_name) )
273277 . collect :: < Vec < _ > > ( ) ;
274278
279+ let field_attrs = input. field_attrs . iter ( )
280+ . map ( |attr| & attr. slice_mut ) . collect :: < Vec < _ > > ( ) ;
281+
275282 let mut generated = quote ! {
276283 /// A mutable slice of
277284 #[ doc = #doc_url]
@@ -283,6 +290,7 @@ pub fn derive_mut(input: &Input) -> TokenStream {
283290 #visibility struct #slice_mut_name<' a> {
284291 #(
285292 #[ doc = #fields_doc]
293+ #( #[ #field_attrs] ) *
286294 pub #fields_names_1: & ' a mut [ #fields_types] ,
287295 ) *
288296 }
Original file line number Diff line number Diff line change @@ -30,7 +30,9 @@ fn eq_test() {
3030#[ derive( StructOfArray ) ]
3131#[ soa_derive( PartialEq , Debug , Serialize , Deserialize ) ]
3232pub struct Point {
33+ #[ soa_attr( Slice , deprecated) ]
3334 pub x : f32 ,
35+ #[ soa_attr( SliceMut , deprecated) ]
3436 pub y : f32 ,
3537 #[ soa_attr( Vec , serde( skip) ) ]
3638 pub meta : bool
@@ -51,5 +53,16 @@ fn serde_skip_test() -> Result<(), serde_json::Error> {
5153 y: vec![ 2.0 , 4.0 ] ,
5254 meta: vec![ ]
5355 } ) ;
56+ {
57+ let slice = soa. as_slice ( ) ;
58+ let _ = slice. x [ 0 ] ; // Should have a deprecate warning
59+ let _ = slice. y [ 0 ] ; // Should not have a deprecate warning
60+ }
61+ {
62+ let slice = soa. as_mut_slice ( ) ;
63+ let _ = slice. y [ 0 ] ; // Should have a deprecate warning
64+ let _ = slice. x [ 0 ] ; // Should not have a deprecate warning
65+
66+ }
5467 Ok ( ( ) )
5568}
You can’t perform that action at this time.
0 commit comments