• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

bitcoindevkit / bdk / 11049850078

26 Sep 2024 09:52AM UTC coverage: 82.592%. Remained the same
11049850078

Pull #1625

github

web-flow
Merge a4cf905d7 into 2cf46a2a9
Pull Request #1625: feat(chain,core)!: move `Merge` to `bdk_core`

21 of 33 new or added lines in 1 file covered. (63.64%)

11297 of 13678 relevant lines covered (82.59%)

15177.28 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

63.64
/crates/core/src/merge.rs
1
use crate::alloc::vec::Vec;
2
use crate::collections::{BTreeMap, BTreeSet};
3

4
/// Trait that makes an object mergeable.
5
pub trait Merge: Default {
6
    /// Merge another object of the same type onto `self`.
7
    fn merge(&mut self, other: Self);
8

9
    /// Returns whether the structure is considered empty.
10
    fn is_empty(&self) -> bool;
11

12
    /// Take the value, replacing it with the default value.
13
    fn take(&mut self) -> Option<Self> {
80✔
14
        if self.is_empty() {
80✔
NEW
15
            None
×
16
        } else {
17
            Some(core::mem::take(self))
80✔
18
        }
19
    }
80✔
20
}
21

22
impl<K: Ord, V> Merge for BTreeMap<K, V> {
23
    fn merge(&mut self, other: Self) {
49,632✔
24
        // We use `extend` instead of `BTreeMap::append` due to performance issues with `append`.
49,632✔
25
        // Refer to https://github.com/rust-lang/rust/issues/34666#issuecomment-675658420
49,632✔
26
        BTreeMap::extend(self, other)
49,632✔
27
    }
49,632✔
28

NEW
29
    fn is_empty(&self) -> bool {
×
NEW
30
        BTreeMap::is_empty(self)
×
NEW
31
    }
×
32
}
33

34
impl<T: Ord> Merge for BTreeSet<T> {
35
    fn merge(&mut self, other: Self) {
450✔
36
        // We use `extend` instead of `BTreeMap::append` due to performance issues with `append`.
450✔
37
        // Refer to https://github.com/rust-lang/rust/issues/34666#issuecomment-675658420
450✔
38
        BTreeSet::extend(self, other)
450✔
39
    }
450✔
40

41
    fn is_empty(&self) -> bool {
437✔
42
        BTreeSet::is_empty(self)
437✔
43
    }
437✔
44
}
45

46
impl<T> Merge for Vec<T> {
NEW
47
    fn merge(&mut self, mut other: Self) {
×
NEW
48
        Vec::append(self, &mut other)
×
NEW
49
    }
×
50

NEW
51
    fn is_empty(&self) -> bool {
×
NEW
52
        Vec::is_empty(self)
×
NEW
53
    }
×
54
}
55

56
macro_rules! impl_merge_for_tuple {
57
    ($($a:ident $b:tt)*) => {
58
        impl<$($a),*> Merge for ($($a,)*) where $($a: Merge),* {
59

60
            fn merge(&mut self, _other: Self) {
7,406✔
61
                $(Merge::merge(&mut self.$b, _other.$b) );*
7,406✔
62
            }
7,406✔
63

NEW
64
            fn is_empty(&self) -> bool {
×
NEW
65
                $(Merge::is_empty(&self.$b) && )* true
×
66
            }
2,346✔
67
        }
68
    }
69
}
70

71
impl_merge_for_tuple!();
72
impl_merge_for_tuple!(T0 0);
73
impl_merge_for_tuple!(T0 0 T1 1);
74
impl_merge_for_tuple!(T0 0 T1 1 T2 2);
75
impl_merge_for_tuple!(T0 0 T1 1 T2 2 T3 3);
76
impl_merge_for_tuple!(T0 0 T1 1 T2 2 T3 3 T4 4);
77
impl_merge_for_tuple!(T0 0 T1 1 T2 2 T3 3 T4 4 T5 5);
78
impl_merge_for_tuple!(T0 0 T1 1 T2 2 T3 3 T4 4 T5 5 T6 6);
79
impl_merge_for_tuple!(T0 0 T1 1 T2 2 T3 3 T4 4 T5 5 T6 6 T7 7);
80
impl_merge_for_tuple!(T0 0 T1 1 T2 2 T3 3 T4 4 T5 5 T6 6 T7 7 T8 8);
81
impl_merge_for_tuple!(T0 0 T1 1 T2 2 T3 3 T4 4 T5 5 T6 6 T7 7 T8 8 T9 9);
82
impl_merge_for_tuple!(T0 0 T1 1 T2 2 T3 3 T4 4 T5 5 T6 6 T7 7 T8 8 T9 9 T10 10);
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc