~ireas/public-inbox

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
1

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

Robin Appelman <robin@icewind.nl>
Details
Message ID
<20230402150421.1958059-1-robin@icewind.nl>
DKIM signature
missing
Download raw message
Patch: +10 -0
---
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] build failed

builds.sr.ht <builds@sr.ht>
Details
Message ID
<CRMD5VOEV6X2.1OHTLSXEBZMV6@cirno2>
In-Reply-To
<20230402150421.1958059-1-robin@icewind.nl> (view parent)
DKIM signature
missing
Download raw message
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]: 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
Reply to thread Export thread (mbox)