@@ -12,6 +12,8 @@ pub struct Input {
12
12
pub name : Ident ,
13
13
/// The list of fields in the struct
14
14
pub fields : Vec < Field > ,
15
+ /// Additional attributes requested with `#[soa_attr(...)]` on fields
16
+ pub field_attrs : Vec < ExtraAttributes > ,
15
17
/// The struct overall visibility
16
18
pub visibility : Visibility ,
17
19
/// Additional attributes requested with `#[soa_attr(...)]` or
@@ -145,8 +147,23 @@ fn create_derive_meta(path: Path) -> Meta {
145
147
146
148
impl Input {
147
149
pub fn new ( input : DeriveInput ) -> Input {
148
- let fields = match input. data {
149
- Data :: Struct ( s) => s. fields . iter ( ) . cloned ( ) . collect :: < Vec < _ > > ( ) ,
150
+ let mut fields = Vec :: new ( ) ;
151
+ let mut field_attrs = Vec :: new ( ) ;
152
+ match input. data {
153
+ Data :: Struct ( s) => {
154
+ for field in s. fields . iter ( ) {
155
+ let mut extra_attrs = ExtraAttributes :: new ( ) ;
156
+ fields. push ( field. clone ( ) ) ;
157
+ for attr in & field. attrs {
158
+ if let Ok ( meta) = attr. parse_meta ( ) {
159
+ if meta. path ( ) . is_ident ( "soa_attr" ) {
160
+ extra_attrs. parse ( & meta) ;
161
+ }
162
+ }
163
+ }
164
+ field_attrs. push ( extra_attrs) ;
165
+ }
166
+ }
150
167
_ => panic ! ( "#[derive(StructOfArray)] only supports struct" ) ,
151
168
} ;
152
169
@@ -201,6 +218,7 @@ impl Input {
201
218
visibility : input. vis ,
202
219
attrs : extra_attrs,
203
220
derive_clone,
221
+ field_attrs,
204
222
}
205
223
}
206
224
0 commit comments