From c6ef5a6d72027e6fe6aa031844d39dc6fb74fc7e Mon Sep 17 00:00:00 2001 From: "Felipe S. S. Schneider" Date: Tue, 5 Mar 2024 12:46:21 -0300 Subject: [PATCH] feat: implement Default for slices and mut slices This will silently ignore Default derive requests as well. --- soa-derive-internal/src/input.rs | 6 ++++-- soa-derive-internal/src/slice.rs | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/soa-derive-internal/src/input.rs b/soa-derive-internal/src/input.rs index 5b26656..4466696 100644 --- a/soa-derive-internal/src/input.rs +++ b/soa-derive-internal/src/input.rs @@ -116,8 +116,10 @@ impl Input { match meta.path.get_ident() { Some(ident) => { assert!(ident != "Copy", "can not derive Copy for SoA vectors"); - assert!(ident != "Default", "Default is already derived for SoA vectors"); - extra_attrs.add_derive(ident); + if ident != "Default" { + // ignore as Default is already derived for SoA vectors, slices and mut slices + extra_attrs.add_derive(ident); + } } None => { panic!( diff --git a/soa-derive-internal/src/slice.rs b/soa-derive-internal/src/slice.rs index 9b7697a..832f163 100644 --- a/soa-derive-internal/src/slice.rs +++ b/soa-derive-internal/src/slice.rs @@ -63,6 +63,7 @@ pub fn derive(input: &Input) -> TokenStream { #[allow(dead_code)] #[derive(Copy, Clone)] #(#[#attrs])* + #[derive(Default)] #visibility struct #slice_name<'a> { #( /// slice of ` @@ -337,6 +338,7 @@ pub fn derive_mut(input: &Input) -> TokenStream { /// . #[allow(dead_code)] #(#[#attrs])* + #[derive(Default)] #visibility struct #slice_mut_name<'a> { #( /// slice of `