From: Matt Corallo Date: Sat, 11 May 2024 18:51:48 +0000 (+0000) Subject: [UPSTREAM] Make `offers::Amount` `Copy` and export it in bindings X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=bc7dc7ad8c7d91ffda5c356bef81c5b349fae6e8;p=rust-lightning [UPSTREAM] Make `offers::Amount` `Copy` and export it in bindings `Amount` is less than two pointers long, so there's no reason it shouldn't be `Copy`. Further, because its an enum, bindings can't map a reference to it in an `Option`. Thus, here, we simply make it `Copy` and return it in `Option`s rather than a reference to it. --- diff --git a/lightning/src/offers/invoice.rs b/lightning/src/offers/invoice.rs index 6f907d785..1f19c5971 100644 --- a/lightning/src/offers/invoice.rs +++ b/lightning/src/offers/invoice.rs @@ -697,7 +697,7 @@ macro_rules! invoice_accessors { ($self: ident, $contents: expr) => { /// /// [`Offer`]: crate::offers::offer::Offer /// [`Offer::amount`]: crate::offers::offer::Offer::amount - pub fn amount(&$self) -> Option<&Amount> { + pub fn amount(&$self) -> Option { $contents.amount() } @@ -944,7 +944,7 @@ impl InvoiceContents { } } - fn amount(&self) -> Option<&Amount> { + fn amount(&self) -> Option { match self { InvoiceContents::ForOffer { invoice_request, .. } => invoice_request.inner.offer.amount(), diff --git a/lightning/src/offers/offer.rs b/lightning/src/offers/offer.rs index 6df9b30a4..2a492fc91 100644 --- a/lightning/src/offers/offer.rs +++ b/lightning/src/offers/offer.rs @@ -582,7 +582,7 @@ macro_rules! offer_accessors { ($self: ident, $contents: expr) => { } /// The minimum amount required for a successful payment of a single item. - pub fn amount(&$self) -> Option<&$crate::offers::offer::Amount> { + pub fn amount(&$self) -> Option<$crate::offers::offer::Amount> { $contents.amount() } @@ -808,8 +808,8 @@ impl OfferContents { self.metadata.as_ref().and_then(|metadata| metadata.as_bytes()) } - pub fn amount(&self) -> Option<&Amount> { - self.amount.as_ref() + pub fn amount(&self) -> Option { + self.amount } pub fn description(&self) -> Option { @@ -982,7 +982,7 @@ impl Writeable for OfferContents { /// The minimum amount required for an item in an [`Offer`], denominated in either bitcoin or /// another currency. -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Copy, Debug, PartialEq)] pub enum Amount { /// An amount of bitcoin. Bitcoin {