Skip to content

Commit 80b8df8

Browse files
committed
feat(chain): impl Append for Option<T>
1 parent f108093 commit 80b8df8

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

crates/chain/src/tx_data_traits.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,17 @@ impl<T> Append for Vec<T> {
128128
}
129129
}
130130

131+
impl<T> Append for Option<T> {
132+
// If other is Some then replace self's value with other's value, if other is None do nothing.
133+
fn append(&mut self, other: Self) {
134+
other.and_then(|v| self.replace(v));
135+
}
136+
137+
fn is_empty(&self) -> bool {
138+
self.is_none()
139+
}
140+
}
141+
131142
macro_rules! impl_append_for_tuple {
132143
($($a:ident $b:tt)*) => {
133144
impl<$($a),*> Append for ($($a,)*) where $($a: Append),* {

crates/chain/src/tx_graph.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ impl<A: Clone + Ord> TxGraph<A> {
562562
let tx_entry = self
563563
.txs
564564
.entry(outpoint.txid)
565-
.or_insert_with(Default::default);
565+
.or_default();
566566

567567
match tx_entry {
568568
(TxNodeInternal::Whole(_), _, _) => { /* do nothing since we already have full tx */
@@ -575,13 +575,13 @@ impl<A: Clone + Ord> TxGraph<A> {
575575

576576
for (anchor, txid) in changeset.anchors {
577577
if self.anchors.insert((anchor.clone(), txid)) {
578-
let (_, anchors, _) = self.txs.entry(txid).or_insert_with(Default::default);
578+
let (_, anchors, _) = self.txs.entry(txid).or_default();
579579
anchors.insert(anchor);
580580
}
581581
}
582582

583583
for (txid, new_last_seen) in changeset.last_seen {
584-
let (_, _, last_seen) = self.txs.entry(txid).or_insert_with(Default::default);
584+
let (_, _, last_seen) = self.txs.entry(txid).or_default();
585585
if new_last_seen > *last_seen {
586586
*last_seen = new_last_seen;
587587
}

0 commit comments

Comments
 (0)