Skip to content

Commit 2e18505

Browse files
committed
Impl default and display for invoice fields
1 parent 6e40e5f commit 2e18505

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

lightning-invoice/src/lib.rs

+15
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,21 @@ pub enum Bolt11InvoiceDescription<'f> {
269269
Hash(&'f Sha256),
270270
}
271271

272+
impl<'f> Default for Bolt11InvoiceDescription<'f> {
273+
fn default() -> Self {
274+
Bolt11InvoiceDescription::Direct(&Description::default())
275+
}
276+
}
277+
278+
impl<'f> Display for Bolt11InvoiceDescription<'f> {
279+
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
280+
match self {
281+
Bolt11InvoiceDescription::Direct(desc) => write!(f, "{}", desc),
282+
Bolt11InvoiceDescription::Hash(hash) => write!(f, "{}", hash.0),
283+
}
284+
}
285+
}
286+
272287
/// Represents a signed [`RawBolt11Invoice`] with cached hash. The signature is not checked and may be
273288
/// invalid.
274289
///

0 commit comments

Comments
 (0)