Skip to content

Commit

Permalink
fix: avoid adding feature out of crate
Browse files Browse the repository at this point in the history
  • Loading branch information
yanganto committed Jan 10, 2025
1 parent 43c1bfd commit bbcbae9
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ members = [

[workspace.package]
authors = ["Antonio Yang <[email protected]>"]
version = "0.8.6"
version = "0.8.7"
edition = "2021"
categories = ["development-tools"]
keywords = ["struct", "patch", "macro", "derive", "overlay"]
Expand Down
52 changes: 45 additions & 7 deletions struct-patch-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,48 @@ impl Patch {
})
.collect::<Vec<_>>();

#[cfg(feature = "op")]
#[cfg(all(feature = "op", not(feature = "merge")))]
let op_impl = quote! {
impl #generics core::ops::Shl<#name #generics> for #struct_name #generics #where_clause {
type Output = Self;

fn shl(mut self, rhs: #name #generics) -> Self {
struct_patch::traits::Patch::apply(&mut self, rhs);
self
}
}

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

fn add(mut self, rhs: Self) -> Self {
Self {
#(
#renamed_field_names: match (self.#renamed_field_names, rhs.#renamed_field_names) {
(Some(a), Some(b)) => {
#addable_handles
},
(Some(a), None) => Some(a),
(None, Some(b)) => Some(b),
(None, None) => None,
},
)*
#(
#original_field_names: match (self.#original_field_names, rhs.#original_field_names) {
(Some(a), Some(b)) => {
#addable_handles
},
(Some(a), None) => Some(a),
(None, Some(b)) => Some(b),
(None, None) => None,
},
)*
}
}
}
};

#[cfg(feature = "merge")]
let op_impl = quote! {
impl #generics core::ops::Shl<#name #generics> for #struct_name #generics #where_clause {
type Output = Self;
Expand All @@ -166,7 +207,6 @@ impl Patch {
}
}

#[cfg(feature = "merge")]
impl #generics core::ops::Shl<#name #generics> for #name #generics #where_clause {
type Output = Self;

Expand Down Expand Up @@ -204,6 +244,7 @@ impl Patch {
}
}
};

#[cfg(not(feature = "op"))]
let op_impl = quote!();

Expand Down Expand Up @@ -446,7 +487,7 @@ impl Field {
ADDABLE => {
return Err(syn::Error::new(
ident.span(),
"`addable` needs `op` feature"
"`addable` needs `op` feature",
));
}
#[cfg(feature = "op")]
Expand All @@ -457,10 +498,7 @@ impl Field {
}
#[cfg(not(feature = "op"))]
ADD => {
return Err(syn::Error::new(
ident.span(),
"`add` needs `op` feature"
));
return Err(syn::Error::new(ident.span(), "`add` needs `op` feature"));
}
_ => {
return Err(meta.error(format_args!(
Expand Down
2 changes: 1 addition & 1 deletion struct-patch/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ license.workspace = true
readme.workspace = true

[dependencies]
struct-patch-derive = { version = "=0.8.6", path = "../struct-patch-derive" }
struct-patch-derive = { version = "=0.8.7", path = "../struct-patch-derive" }

[dev-dependencies]
serde_json = "1.0"
Expand Down

0 comments on commit bbcbae9

Please sign in to comment.