~ireas/public-inbox

merge-rs: add merge strategy that overwrite the default v1 PROPOSED

Robin Appelman: 1
 add merge strategy that overwrite the default

 1 files changed, 10 insertions(+), 0 deletions(-)
#966985 archlinux-msrv.yml failed
#966986 archlinux.yml failed
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~ireas/public-inbox/patches/40129/mbox | git am -3
Learn more about email & git

[PATCH merge-rs] add merge strategy that overwrite the default Export this patch

---
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
merge-rs/patches: FAILED in 4m53s

[add merge strategy that overwrite the default][0] from [Robin Appelman][1]

[0]: https://lists.sr.ht/~ireas/public-inbox/patches/40129
[1]: mailto:robin@icewind.nl

✗ #966985 FAILED merge-rs/patches/archlinux-msrv.yml https://builds.sr.ht/~ireas/job/966985
✗ #966986 FAILED merge-rs/patches/archlinux.yml      https://builds.sr.ht/~ireas/job/966986