]> git.bitcoin.ninja Git - rust-lightning/commit
Use &mut self in invoice updaters, not take-self-return-Self 2022-02-no-copy-invoice-fields
authorMatt Corallo <git@bluematt.me>
Wed, 23 Feb 2022 18:31:41 +0000 (18:31 +0000)
committerMatt Corallo <git@bluematt.me>
Wed, 23 Feb 2022 20:17:36 +0000 (20:17 +0000)
commitb7d57ea83ebe1cebb56389fb540fc7c5207d8cb3
treeaff406113283c3e7ab6d9f2596609abadffd3562
parente43cfe135a5b68620cd51b9b982362c272b4ef77
Use &mut self in invoice updaters, not take-self-return-Self

The take-self-return-Self idiom in Rust is substantially less
usable than it is in Java, where its more common. Because we have
to take self by move, it prevents using the update methods to
actually update features, something we occasionally want to do.

See, eg, the change in lightning-invoice where we previously had
to copy and re-create an entire vec of fields just to update the
features field, which is nuts.

There are a few places where this makes things a little less clean,
but the tradeoff to enable more effecient and broader uses of the
update methods seems worth it.
lightning-invoice/src/lib.rs
lightning/src/ln/features.rs
lightning/src/routing/router.rs