feat(chain)!: add take convenience method to Append trait
This is useful if the caller wishes to use the type as a staging area. This is breaking as `Append` has a `Default` bound now.
This commit is contained in:
@@ -114,12 +114,21 @@ pub trait AnchorFromBlockPosition: Anchor {
|
||||
}
|
||||
|
||||
/// Trait that makes an object appendable.
|
||||
pub trait Append {
|
||||
pub trait Append: Default {
|
||||
/// Append another object of the same type onto `self`.
|
||||
fn append(&mut self, other: Self);
|
||||
|
||||
/// Returns whether the structure is considered empty.
|
||||
fn is_empty(&self) -> bool;
|
||||
|
||||
/// Take the value, replacing it with the default value.
|
||||
fn take(&mut self) -> Option<Self> {
|
||||
if self.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(core::mem::take(self))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<K: Ord, V> Append for BTreeMap<K, V> {
|
||||
|
||||
@@ -2291,11 +2291,7 @@ impl Wallet {
|
||||
|
||||
/// Take the staged [`ChangeSet`] to be persisted now (if any).
|
||||
pub fn take_staged(&mut self) -> Option<ChangeSet> {
|
||||
if self.stage.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(core::mem::take(&mut self.stage))
|
||||
}
|
||||
self.stage.take()
|
||||
}
|
||||
|
||||
/// Get a reference to the inner [`TxGraph`].
|
||||
|
||||
Reference in New Issue
Block a user