Skip to content

Commit bbcbae9

Browse files
committed
fix: avoid adding feature out of crate
1 parent 43c1bfd commit bbcbae9

File tree

3 files changed

+47
-9
lines changed

3 files changed

+47
-9
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ members = [
77

88
[workspace.package]
99
authors = ["Antonio Yang <yanganto@gmail.com>"]
10-
version = "0.8.6"
10+
version = "0.8.7"
1111
edition = "2021"
1212
categories = ["development-tools"]
1313
keywords = ["struct", "patch", "macro", "derive", "overlay"]

struct-patch-derive/src/lib.rs

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,48 @@ impl Patch {
155155
})
156156
.collect::<Vec<_>>();
157157

158-
#[cfg(feature = "op")]
158+
#[cfg(all(feature = "op", not(feature = "merge")))]
159+
let op_impl = quote! {
160+
impl #generics core::ops::Shl<#name #generics> for #struct_name #generics #where_clause {
161+
type Output = Self;
162+
163+
fn shl(mut self, rhs: #name #generics) -> Self {
164+
struct_patch::traits::Patch::apply(&mut self, rhs);
165+
self
166+
}
167+
}
168+
169+
impl #generics core::ops::Add<Self> for #name #generics #where_clause {
170+
type Output = Self;
171+
172+
fn add(mut self, rhs: Self) -> Self {
173+
Self {
174+
#(
175+
#renamed_field_names: match (self.#renamed_field_names, rhs.#renamed_field_names) {
176+
(Some(a), Some(b)) => {
177+
#addable_handles
178+
},
179+
(Some(a), None) => Some(a),
180+
(None, Some(b)) => Some(b),
181+
(None, None) => None,
182+
},
183+
)*
184+
#(
185+
#original_field_names: match (self.#original_field_names, rhs.#original_field_names) {
186+
(Some(a), Some(b)) => {
187+
#addable_handles
188+
},
189+
(Some(a), None) => Some(a),
190+
(None, Some(b)) => Some(b),
191+
(None, None) => None,
192+
},
193+
)*
194+
}
195+
}
196+
}
197+
};
198+
199+
#[cfg(feature = "merge")]
159200
let op_impl = quote! {
160201
impl #generics core::ops::Shl<#name #generics> for #struct_name #generics #where_clause {
161202
type Output = Self;
@@ -166,7 +207,6 @@ impl Patch {
166207
}
167208
}
168209

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

@@ -204,6 +244,7 @@ impl Patch {
204244
}
205245
}
206246
};
247+
207248
#[cfg(not(feature = "op"))]
208249
let op_impl = quote!();
209250

@@ -446,7 +487,7 @@ impl Field {
446487
ADDABLE => {
447488
return Err(syn::Error::new(
448489
ident.span(),
449-
"`addable` needs `op` feature"
490+
"`addable` needs `op` feature",
450491
));
451492
}
452493
#[cfg(feature = "op")]
@@ -457,10 +498,7 @@ impl Field {
457498
}
458499
#[cfg(not(feature = "op"))]
459500
ADD => {
460-
return Err(syn::Error::new(
461-
ident.span(),
462-
"`add` needs `op` feature"
463-
));
501+
return Err(syn::Error::new(ident.span(), "`add` needs `op` feature"));
464502
}
465503
_ => {
466504
return Err(meta.error(format_args!(

struct-patch/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ license.workspace = true
1111
readme.workspace = true
1212

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

1616
[dev-dependencies]
1717
serde_json = "1.0"

0 commit comments

Comments
 (0)