Skip to content

Commit 7fb99a8

Browse files
schneiderfelipeLuthaf
authored andcommitted
feat: implement ::new by wrapping ::default
1 parent 2508c12 commit 7fb99a8

File tree

2 files changed

+1
-13
lines changed

2 files changed

+1
-13
lines changed

soa-derive-internal/src/vec.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,6 @@ pub fn derive(input: &Input) -> TokenStream {
3939
|_, field_type| quote! { Vec<#field_type> },
4040
).collect::<Vec<_>>();
4141

42-
let vec_new = input.map_fields_nested_or(
43-
|_, field_type| quote! { <#field_type as StructOfArray>::Type::new()},
44-
|_, _| quote! { Vec::new() },
45-
).collect::<Vec<_>>();
46-
4742
let vec_with_capacity = input.map_fields_nested_or(
4843
|_, field_type| quote! { <#field_type as StructOfArray>::Type::with_capacity(capacity) },
4944
|_, _| quote! { Vec::with_capacity(capacity) },
@@ -96,9 +91,7 @@ pub fn derive(input: &Input) -> TokenStream {
9691
#[doc = #vec_name_str]
9792
/// ::new()`](https://doc.rust-lang.org/std/vec/struct.Vec.html#method.new)
9893
pub fn new() -> #vec_name {
99-
#vec_name {
100-
#( #fields_names: #vec_new, )*
101-
}
94+
Default::default()
10295
}
10396

10497
/// Similar to [`

tests/vec.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@ fn ty() {
1010
let _: <Particle as StructOfArray>::Type = ParticleVec::new();
1111
}
1212

13-
#[test]
14-
fn default() {
15-
assert_eq!(ParticleVec::new(), ParticleVec::default());
16-
}
17-
1813
#[test]
1914
fn push() {
2015
let mut particles = ParticleVec::new();

0 commit comments

Comments
 (0)