---
Adds a merge stratagy that overwrites the value if it's equal to
`T::default()`.
Since this is generic enough to cover a wide range of types (bool,
Option, String, int, etc..), setting it as the default merge strategy
for a struct *should* be enough to cover a large number of cases in a
sensible manner.
src/lib.rs | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/src/lib.rs b/src/lib.rs
index ab9b4ab..f1ffe1d 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -299,3 +299,13 @@ pub mod hashmap {
}
}
}
+
+/// Merge strategies for Default + Eq types.
+pub mod default {
+ /// Overwrite left with right if the value of left is equal to the default for the type.
+ pub fn overwrite_default<T: Default + Eq>(left: &mut T, right: T) {
+ if left == &T::default() {
+ *left = right;
+ }
+ }
+}
--
2.38.4