Skip to content

Commit 5d9007a

Browse files
committed
feat(chain): impl Append for Option<T>
fix fmt crates/chain
1 parent f741122 commit 5d9007a

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
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 & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -559,10 +559,7 @@ impl<A: Clone + Ord> TxGraph<A> {
559559
}
560560

561561
for (outpoint, txout) in changeset.txouts {
562-
let tx_entry = self
563-
.txs
564-
.entry(outpoint.txid)
565-
.or_insert_with(Default::default);
562+
let tx_entry = self.txs.entry(outpoint.txid).or_default();
566563

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

576573
for (anchor, txid) in changeset.anchors {
577574
if self.anchors.insert((anchor.clone(), txid)) {
578-
let (_, anchors, _) = self.txs.entry(txid).or_insert_with(Default::default);
575+
let (_, anchors, _) = self.txs.entry(txid).or_default();
579576
anchors.insert(anchor);
580577
}
581578
}
582579

583580
for (txid, new_last_seen) in changeset.last_seen {
584-
let (_, _, last_seen) = self.txs.entry(txid).or_insert_with(Default::default);
581+
let (_, _, last_seen) = self.txs.entry(txid).or_default();
585582
if new_last_seen > *last_seen {
586583
*last_seen = new_last_seen;
587584
}

0 commit comments

Comments
 (0)