[bdk_chain_redesign] Introduce Append trait for additions
Before, we were using `core::ops::AddAsign` but it was not the most appropriate.
This commit is contained in:
@@ -14,14 +14,13 @@
|
||||
//! [`KeychainChangeSet`]s.
|
||||
//!
|
||||
//! [`SpkTxOutIndex`]: crate::SpkTxOutIndex
|
||||
use core::ops::AddAssign;
|
||||
|
||||
use crate::{
|
||||
chain_graph::{self, ChainGraph},
|
||||
collections::BTreeMap,
|
||||
sparse_chain::ChainPosition,
|
||||
tx_graph::TxGraph,
|
||||
ForEachTxOut,
|
||||
Append, ForEachTxOut,
|
||||
};
|
||||
|
||||
#[cfg(feature = "miniscript")]
|
||||
@@ -71,12 +70,12 @@ impl<K> DerivationAdditions<K> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<K: Ord> DerivationAdditions<K> {
|
||||
impl<K: Ord> Append for DerivationAdditions<K> {
|
||||
/// Append another [`DerivationAdditions`] into self.
|
||||
///
|
||||
/// If the keychain already exists, increase the index when the other's index > self's index.
|
||||
/// If the keychain did not exist, append the new keychain.
|
||||
pub fn append(&mut self, mut other: Self) {
|
||||
fn append(&mut self, mut other: Self) {
|
||||
self.0.iter_mut().for_each(|(key, index)| {
|
||||
if let Some(other_index) = other.0.remove(key) {
|
||||
*index = other_index.max(*index);
|
||||
@@ -87,12 +86,6 @@ impl<K: Ord> DerivationAdditions<K> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<K: Ord> AddAssign for DerivationAdditions<K> {
|
||||
fn add_assign(&mut self, rhs: Self) {
|
||||
self.append(rhs)
|
||||
}
|
||||
}
|
||||
|
||||
impl<K> Default for DerivationAdditions<K> {
|
||||
fn default() -> Self {
|
||||
Self(Default::default())
|
||||
|
||||
Reference in New Issue
Block a user