Skip to content

Commit c6b5dc2

Browse files
committed
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.
1 parent 2802993 commit c6b5dc2

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

lightning/src/offers/invoice.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ macro_rules! invoice_accessors { ($self: ident, $contents: expr) => {
697697
///
698698
/// [`Offer`]: crate::offers::offer::Offer
699699
/// [`Offer::amount`]: crate::offers::offer::Offer::amount
700-
pub fn amount(&$self) -> Option<&Amount> {
700+
pub fn amount(&$self) -> Option<Amount> {
701701
$contents.amount()
702702
}
703703

@@ -944,7 +944,7 @@ impl InvoiceContents {
944944
}
945945
}
946946

947-
fn amount(&self) -> Option<&Amount> {
947+
fn amount(&self) -> Option<Amount> {
948948
match self {
949949
InvoiceContents::ForOffer { invoice_request, .. } =>
950950
invoice_request.inner.offer.amount(),

lightning/src/offers/offer.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ macro_rules! offer_accessors { ($self: ident, $contents: expr) => {
582582
}
583583

584584
/// The minimum amount required for a successful payment of a single item.
585-
pub fn amount(&$self) -> Option<&$crate::offers::offer::Amount> {
585+
pub fn amount(&$self) -> Option<$crate::offers::offer::Amount> {
586586
$contents.amount()
587587
}
588588

@@ -808,8 +808,8 @@ impl OfferContents {
808808
self.metadata.as_ref().and_then(|metadata| metadata.as_bytes())
809809
}
810810

811-
pub fn amount(&self) -> Option<&Amount> {
812-
self.amount.as_ref()
811+
pub fn amount(&self) -> Option<Amount> {
812+
self.amount
813813
}
814814

815815
pub fn description(&self) -> Option<PrintableString> {
@@ -982,7 +982,7 @@ impl Writeable for OfferContents {
982982

983983
/// The minimum amount required for an item in an [`Offer`], denominated in either bitcoin or
984984
/// another currency.
985-
#[derive(Clone, Debug, PartialEq)]
985+
#[derive(Clone, Copy, Debug, PartialEq)]
986986
pub enum Amount {
987987
/// An amount of bitcoin.
988988
Bitcoin {

0 commit comments

Comments
 (0)