Skip to content

Commit

Permalink
feat: implement Default for slices and mut slices
Browse files Browse the repository at this point in the history
This will silently ignore Default derive requests as well.
  • Loading branch information
schneiderfelipe authored and Luthaf committed Mar 18, 2024
1 parent 7fb99a8 commit c6ef5a6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 4 additions & 2 deletions soa-derive-internal/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down
2 changes: 2 additions & 0 deletions soa-derive-internal/src/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 `
Expand Down Expand Up @@ -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 `
Expand Down

0 comments on commit c6ef5a6

Please sign in to comment.