Skip to content

Commit b5c98a3

Browse files
committed
refactor: derive_clone from ExtraAttributes move to Input
1 parent 404a443 commit b5c98a3

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

soa-derive-internal/src/input.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ pub struct Input {
1717
/// Additional attributes requested with `#[soa_attr(...)]` or
1818
/// `#[soa_derive()]`
1919
pub attrs: ExtraAttributes,
20-
}
2120

22-
pub struct ExtraAttributes {
2321
// did the user explicitly asked us to derive clone?
2422
pub derive_clone: bool,
23+
}
2524

25+
pub struct ExtraAttributes {
2626
pub vec: Vec<Meta>,
2727
pub slice: Vec<Meta>,
2828
pub slice_mut: Vec<Meta>,
@@ -35,7 +35,6 @@ pub struct ExtraAttributes {
3535
impl ExtraAttributes {
3636
fn new() -> ExtraAttributes {
3737
ExtraAttributes {
38-
derive_clone: false,
3938
vec: Vec::new(),
4039
slice: Vec::new(),
4140
slice_mut: Vec::new(),
@@ -130,9 +129,6 @@ impl ExtraAttributes {
130129
// always add this derive to the Vec struct
131130
self.vec.push(derive);
132131

133-
if path.is_ident("Clone") {
134-
self.derive_clone = true;
135-
}
136132
}
137133
}
138134

@@ -160,6 +156,7 @@ impl Input {
160156

161157
let mut extra_attrs = ExtraAttributes::new();
162158

159+
let mut derive_clone = false;
163160
for attr in input.attrs {
164161
if let Ok(meta) = attr.parse_meta() {
165162
if meta.path().is_ident("soa_derive") {
@@ -173,6 +170,9 @@ impl Input {
173170
panic!("can not derive Copy for SoA vectors");
174171
}
175172
extra_attrs.add_derive(path);
173+
if path.is_ident("Clone") {
174+
derive_clone = true;
175+
}
176176
}
177177
NestedMeta::Lit(_) => {
178178
panic!(
@@ -200,6 +200,7 @@ impl Input {
200200
fields: fields,
201201
visibility: input.vis,
202202
attrs: extra_attrs,
203+
derive_clone,
203204
}
204205
}
205206

soa-derive-internal/src/slice.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ pub fn derive(input: &Input) -> TokenStream {
214214
}
215215
};
216216

217-
if input.attrs.derive_clone {
217+
if input.derive_clone {
218218
generated.append_all(quote!{
219219
#[allow(dead_code)]
220220
impl<'a> #slice_name<'a> {
@@ -524,7 +524,7 @@ pub fn derive_mut(input: &Input) -> TokenStream {
524524
}
525525
};
526526

527-
if input.attrs.derive_clone {
527+
if input.derive_clone {
528528
generated.append_all(quote!{
529529
#[allow(dead_code)]
530530
impl<'a> #slice_mut_name<'a> {

soa-derive-internal/src/vec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ pub fn derive(input: &Input) -> TokenStream {
350350
}
351351
};
352352

353-
if input.attrs.derive_clone {
353+
if input.derive_clone {
354354
generated.append_all(quote!{
355355
#[allow(dead_code)]
356356
impl #vec_name {

0 commit comments

Comments
 (0)