Skip to content

Commit

Permalink
Avoid impl Add for generics
Browse files Browse the repository at this point in the history
  • Loading branch information
yanganto committed Aug 9, 2024
1 parent 0ad6210 commit 59c9772
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions struct-patch-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,29 +100,33 @@ impl Patch {
#[cfg(not(feature = "status"))]
let patch_status_impl = quote!();

#[cfg(feature = "add")]
let add_impl = quote! {
impl core::ops::Add<#name #generics> for #struct_name #generics #where_clause {
type Output = Self;

fn add(mut self, rhs: #name #generics) -> Self {
self.apply(rhs);
self
let add_impl = if generics.gt_token.is_none() {
#[cfg(feature = "add")]
quote! {
impl core::ops::Add<#name #generics> for #struct_name #generics #where_clause {
type Output = Self;

fn add(mut self, rhs: #name #generics) -> Self {
self.apply(rhs);
self
}
}
}

impl core::ops::Add<#struct_name #generics> for #name #generics #where_clause {
type Output = #struct_name #generics;
impl core::ops::Add<#struct_name #generics> for #name #generics #where_clause {
type Output = #struct_name #generics;

fn add(mut self, rhs: #struct_name #generics) -> #struct_name #where_clause {
let mut rhs = rhs;
rhs.apply(self);
rhs
fn add(mut self, rhs: #struct_name #generics) -> #struct_name #where_clause {
let mut rhs = rhs;
rhs.apply(self);
rhs
}
}
}
#[cfg(not(feature = "add"))]
quote!()
} else {
quote!()
};
#[cfg(not(feature = "add"))]
let add_impl = quote!();

let patch_impl = quote! {
impl #generics struct_patch::traits::Patch< #name #generics > for #struct_name #generics #where_clause {
Expand Down

0 comments on commit 59c9772

Please sign in to comment.