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

bitcoindevkit / bdk / 11128025252

01 Oct 2024 02:59PM UTC coverage: 82.578%. Remained the same
11128025252

push

github

notmandatory
Merge bitcoindevkit/bdk#1625: feat(chain,core)!: move `Merge` to `bdk_core`

<a class=hub.com/bitcoindevkit/bdk/commit/<a class="double-link" href="https://git"><a class=hub.com/bitcoindevkit/bdk/commit/<a class="double-link" href="https://git"><a class=hub.com/bitcoindevkit/bdk/commit/<a class="double-link" href="https://git"><a class=hub.com/bitcoindevkit/bdk/commit/a4cf905d75ad7e09730b6d0aab5ef6cd2e735c2b">a4cf905d7<a href="https://github.com/bitcoindevkit/bdk/commit/e4ee629f1ee89a14dcd9e624cf74a39fea197155"> feat(file_store): rm `bdk_chain` dependency (志宇)
<a class="double-link" href="https://github.com/bitcoindevkit/bdk/commit/993c4c055354ba6ddb0d81e8e5dbfa1f9bb631ac">993c4c055</a> feat(chain,core)!: move `Merge` to `bdk_core` (志宇)

Pull request description:

  Fixes #1624

  ### Description

  Moving `Merge` into `bdk_core` (from `bdk_chain`) allows persist crates to only depend on `bdk_core`.

  ### Changelog notice

  * Move `Merge` into `bdk_core`.
  * Remove `bdk_chain` dependency from `bdk_file_store`.

  ### Checklists

  #### All Submissions:

  * [x] I've signed all my commits
  * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md)
  * [x] I ran `cargo fmt` and `cargo clippy` before committing

ACKs for top commit:
  LagginTimes:
    ACK a4cf905d75ad7e09730b6d0aab5ef6cd2e735c2b
  oleonardolima:
    ACK a4cf905d75ad7e09730b6d0aab5ef6cd2e735c2b
  ValuedMammal:
    ACK a4cf905d75ad7e09730b6d0aab5ef6cd2e735c2b
  notmandatory:
    ACK a4cf905d75ad7e09730b6d0aab5ef6cd2e735c2b

Tree-SHA512: a94e24e04d295a55f5b7e178bacb338c956

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

11281 of 13661 relevant lines covered (82.58%)

14153.87 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,654✔
24
        // We use `extend` instead of `BTreeMap::append` due to performance issues with `append`.
49,654✔
25
        // Refer to https://github.com/rust-lang/rust/issues/34666#issuecomment-675658420
49,654✔
26
        BTreeMap::extend(self, other)
49,654✔
27
    }
49,654✔
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