From: Matt Corallo Date: Sun, 18 Sep 2022 13:55:08 +0000 (+0000) Subject: Avoid returning a reference to a u64. X-Git-Tag: v0.0.112~33^2 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=refs%2Fheads%2F2022-09-slices-not-vecs;p=rust-lightning Avoid returning a reference to a u64. In c353c3ed7c40e689a3b9fb6730c6dabbd3c92cc5 an accessor method was added which returns an `Option<&u64>`. While this allows Rust to return an 8-byte object, returning a reference to something pointer-sized is a somewhat strange API. Instead, we opt for a straight `Option`, which is sadly somewhat larger on the stack, but is simpler and already supported in the bindings generation. --- diff --git a/lightning-invoice/src/payment.rs b/lightning-invoice/src/payment.rs index 226e8fe4..3b4fe709 100644 --- a/lightning-invoice/src/payment.rs +++ b/lightning-invoice/src/payment.rs @@ -741,8 +741,8 @@ pub struct InFlightHtlcs(HashMap<(u64, bool), u64>); impl InFlightHtlcs { /// Returns liquidity in msat given the public key of the HTLC source, target, and short channel /// id. - pub fn used_liquidity_msat(&self, source: &NodeId, target: &NodeId, channel_scid: u64) -> Option<&u64> { - self.0.get(&(channel_scid, source < target)) + pub fn used_liquidity_msat(&self, source: &NodeId, target: &NodeId, channel_scid: u64) -> Option { + self.0.get(&(channel_scid, source < target)).map(|v| *v) } }