Skip to content

Commit 854d650

Browse files
committed
Linkify lightning-invoice docs
1 parent 48fa2fd commit 854d650

File tree

1 file changed

+38
-33
lines changed

1 file changed

+38
-33
lines changed

lightning-invoice/src/lib.rs

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@
1818
//! invoices and functions to create, encode and decode these. If you just want to use the standard
1919
//! en-/decoding functionality this should get you started:
2020
//!
21-
//! * For parsing use `str::parse::<Invoice>(&self)` (see the docs of `impl FromStr for Invoice`)
22-
//! * For constructing invoices use the `InvoiceBuilder`
23-
//! * For serializing invoices use the `Display`/`ToString` traits
21+
//! * For parsing use `str::parse::<Invoice>(&self)` (see [`Invoice::from_str`])
22+
//! * For constructing invoices use the [`InvoiceBuilder`]
23+
//! * For serializing invoices use the [`Display`]/[`ToString`] traits
24+
//!
25+
//! [`Invoice::from_str`]: crate::Invoice#impl-FromStr
2426
2527
#[cfg(not(any(feature = "std", feature = "no-std")))]
2628
compile_error!("at least one of the `std` or `no-std` features must be enabled");
@@ -160,7 +162,7 @@ pub const DEFAULT_EXPIRY_TIME: u64 = 3600;
160162
/// [`MIN_FINAL_CLTV_EXPIRY_DELTA`]: lightning::ln::channelmanager::MIN_FINAL_CLTV_EXPIRY_DELTA
161163
pub const DEFAULT_MIN_FINAL_CLTV_EXPIRY_DELTA: u64 = 18;
162164

163-
/// Builder for `Invoice`s. It's the most convenient and advised way to use this library. It ensures
165+
/// Builder for [`Invoice`]s. It's the most convenient and advised way to use this library. It ensures
164166
/// that only a semantically and syntactically correct Invoice can be built using it.
165167
///
166168
/// ```
@@ -212,8 +214,8 @@ pub const DEFAULT_MIN_FINAL_CLTV_EXPIRY_DELTA: u64 = 18;
212214
/// # Type parameters
213215
/// The two parameters `D` and `H` signal if the builder already contains the correct amount of the
214216
/// given field:
215-
/// * `D`: exactly one `Description` or `DescriptionHash`
216-
/// * `H`: exactly one `PaymentHash`
217+
/// * `D`: exactly one [`TaggedField::Description`] or [`TaggedField::DescriptionHash`]
218+
/// * `H`: exactly one [`TaggedField::PaymentHash`]
217219
/// * `T`: the timestamp is set
218220
///
219221
/// (C-not exported) as we likely need to manually select one set of boolean type parameters.
@@ -236,9 +238,11 @@ pub struct InvoiceBuilder<D: tb::Bool, H: tb::Bool, T: tb::Bool, C: tb::Bool, S:
236238
/// Represents a syntactically and semantically correct lightning BOLT11 invoice.
237239
///
238240
/// There are three ways to construct an `Invoice`:
239-
/// 1. using `InvoiceBuilder`
240-
/// 2. using `Invoice::from_signed(SignedRawInvoice)`
241-
/// 3. using `str::parse::<Invoice>(&str)`
241+
/// 1. using [`InvoiceBuilder`]
242+
/// 2. using [`Invoice::from_signed`]
243+
/// 3. using `str::parse::<Invoice>(&str)` (see [`Invoice::from_str`])
244+
///
245+
/// [`Invoice::from_str`]: crate::Invoice#impl-FromStr
242246
#[derive(Eq, PartialEq, Debug, Clone, Hash)]
243247
pub struct Invoice {
244248
signed_invoice: SignedRawInvoice,
@@ -258,34 +262,34 @@ pub enum InvoiceDescription<'f> {
258262
Hash(&'f Sha256),
259263
}
260264

261-
/// Represents a signed `RawInvoice` with cached hash. The signature is not checked and may be
265+
/// Represents a signed [`RawInvoice`] with cached hash. The signature is not checked and may be
262266
/// invalid.
263267
///
264268
/// # Invariants
265-
/// The hash has to be either from the deserialized invoice or from the serialized `raw_invoice`.
269+
/// The hash has to be either from the deserialized invoice or from the serialized [`RawInvoice`].
266270
#[derive(Eq, PartialEq, Debug, Clone, Hash)]
267271
pub struct SignedRawInvoice {
268272
/// The rawInvoice that the signature belongs to
269273
raw_invoice: RawInvoice,
270274

271-
/// Hash of the `RawInvoice` that will be used to check the signature.
275+
/// Hash of the [`RawInvoice`] that will be used to check the signature.
272276
///
273277
/// * if the `SignedRawInvoice` was deserialized the hash is of from the original encoded form,
274278
/// since it's not guaranteed that encoding it again will lead to the same result since integers
275279
/// could have been encoded with leading zeroes etc.
276280
/// * if the `SignedRawInvoice` was constructed manually the hash will be the calculated hash
277-
/// from the `RawInvoice`
281+
/// from the [`RawInvoice`]
278282
hash: [u8; 32],
279283

280284
/// signature of the payment request
281285
signature: InvoiceSignature,
282286
}
283287

284-
/// Represents an syntactically correct Invoice for a payment on the lightning network,
288+
/// Represents an syntactically correct [`Invoice`] for a payment on the lightning network,
285289
/// but without the signature information.
286-
/// De- and encoding should not lead to information loss but may lead to different hashes.
290+
/// Decoding and encoding should not lead to information loss but may lead to different hashes.
287291
///
288-
/// For methods without docs see the corresponding methods in `Invoice`.
292+
/// For methods without docs see the corresponding methods in [`Invoice`].
289293
#[derive(Eq, PartialEq, Debug, Clone, Hash)]
290294
pub struct RawInvoice {
291295
/// human readable part
@@ -295,7 +299,7 @@ pub struct RawInvoice {
295299
pub data: RawDataPart,
296300
}
297301

298-
/// Data of the `RawInvoice` that is encoded in the human readable part
302+
/// Data of the [`RawInvoice`] that is encoded in the human readable part.
299303
///
300304
/// (C-not exported) As we don't yet support `Option<Enum>`
301305
#[derive(Eq, PartialEq, Debug, Clone, Hash)]
@@ -310,7 +314,7 @@ pub struct RawHrp {
310314
pub si_prefix: Option<SiPrefix>,
311315
}
312316

313-
/// Data of the `RawInvoice` that is encoded in the data part
317+
/// Data of the [`RawInvoice`] that is encoded in the data part
314318
#[derive(Eq, PartialEq, Debug, Clone, Hash)]
315319
pub struct RawDataPart {
316320
/// generation time of the invoice
@@ -564,7 +568,8 @@ impl<D: tb::Bool, H: tb::Bool, T: tb::Bool, C: tb::Bool, S: tb::Bool> InvoiceBui
564568
}
565569

566570
impl<D: tb::Bool, H: tb::Bool, C: tb::Bool, S: tb::Bool> InvoiceBuilder<D, H, tb::True, C, S> {
567-
/// Builds a `RawInvoice` if no `CreationError` occurred while construction any of the fields.
571+
/// Builds a [`RawInvoice`] if no [`CreationError`] occurred while construction any of the
572+
/// fields.
568573
pub fn build_raw(self) -> Result<RawInvoice, CreationError> {
569574

570575
// If an error occurred at any time before, return it now
@@ -741,17 +746,17 @@ impl SignedRawInvoice {
741746
(self.raw_invoice, self.hash, self.signature)
742747
}
743748

744-
/// The `RawInvoice` which was signed.
749+
/// The [`RawInvoice`] which was signed.
745750
pub fn raw_invoice(&self) -> &RawInvoice {
746751
&self.raw_invoice
747752
}
748753

749-
/// The hash of the `RawInvoice` that was signed.
754+
/// The hash of the [`RawInvoice`] that was signed.
750755
pub fn signable_hash(&self) -> &[u8; 32] {
751756
&self.hash
752757
}
753758

754-
/// InvoiceSignature for the invoice.
759+
/// Signature for the invoice.
755760
pub fn signature(&self) -> &InvoiceSignature {
756761
&self.signature
757762
}
@@ -869,8 +874,8 @@ impl RawInvoice {
869874
)
870875
}
871876

872-
/// Signs the invoice using the supplied `sign_function`. This function MAY fail with an error
873-
/// of type `E`. Since the signature of a `SignedRawInvoice` is not required to be valid there
877+
/// Signs the invoice using the supplied `sign_method`. This function MAY fail with an error of
878+
/// type `E`. Since the signature of a [`SignedRawInvoice`] is not required to be valid there
874879
/// are no constraints regarding the validity of the produced signature.
875880
///
876881
/// (C-not exported) As we don't currently support passing function pointers into methods
@@ -1125,7 +1130,7 @@ impl Invoice {
11251130
Ok(())
11261131
}
11271132

1128-
/// Constructs an `Invoice` from a `SignedRawInvoice` by checking all its invariants.
1133+
/// Constructs an `Invoice` from a [`SignedRawInvoice`] by checking all its invariants.
11291134
/// ```
11301135
/// use lightning_invoice::*;
11311136
///
@@ -1315,7 +1320,7 @@ impl TaggedField {
13151320
impl Description {
13161321

13171322
/// Creates a new `Description` if `description` is at most 1023 __bytes__ long,
1318-
/// returns `CreationError::DescriptionTooLong` otherwise
1323+
/// returns [`CreationError::DescriptionTooLong`] otherwise
13191324
///
13201325
/// Please note that single characters may use more than one byte due to UTF8 encoding.
13211326
pub fn new(description: String) -> Result<Description, CreationError> {
@@ -1326,7 +1331,7 @@ impl Description {
13261331
}
13271332
}
13281333

1329-
/// Returns the underlying description `String`
1334+
/// Returns the underlying description [`String`]
13301335
pub fn into_inner(self) -> String {
13311336
self.0
13321337
}
@@ -1366,7 +1371,7 @@ impl ExpiryTime {
13661371
ExpiryTime(Duration::from_secs(seconds))
13671372
}
13681373

1369-
/// Construct an `ExpiryTime` from a `Duration`, dropping the sub-second part.
1374+
/// Construct an `ExpiryTime` from a [`Duration`], dropping the sub-second part.
13701375
pub fn from_duration(duration: Duration) -> ExpiryTime {
13711376
Self::from_seconds(duration.as_secs())
13721377
}
@@ -1376,7 +1381,7 @@ impl ExpiryTime {
13761381
self.0.as_secs()
13771382
}
13781383

1379-
/// Returns a reference to the underlying `Duration` (=expiry time)
1384+
/// Returns a reference to the underlying [`Duration`] (=expiry time)
13801385
pub fn as_duration(&self) -> &Duration {
13811386
&self.0
13821387
}
@@ -1428,10 +1433,10 @@ impl Deref for SignedRawInvoice {
14281433
}
14291434
}
14301435

1431-
/// Errors that may occur when constructing a new `RawInvoice` or `Invoice`
1436+
/// Errors that may occur when constructing a new [`RawInvoice`] or [`Invoice`]
14321437
#[derive(Eq, PartialEq, Debug, Clone)]
14331438
pub enum CreationError {
1434-
/// The supplied description string was longer than 639 __bytes__ (see [`Description::new(…)`](./struct.Description.html#method.new))
1439+
/// The supplied description string was longer than 639 __bytes__ (see [`Description::new`])
14351440
DescriptionTooLong,
14361441

14371442
/// The specified route has too many hops and can't be encoded
@@ -1472,7 +1477,7 @@ impl Display for CreationError {
14721477
#[cfg(feature = "std")]
14731478
impl std::error::Error for CreationError { }
14741479

1475-
/// Errors that may occur when converting a `RawInvoice` to an `Invoice`. They relate to the
1480+
/// Errors that may occur when converting a [`RawInvoice`] to an [`Invoice`]. They relate to the
14761481
/// requirements sections in BOLT #11
14771482
#[derive(Eq, PartialEq, Debug, Clone)]
14781483
pub enum SemanticError {
@@ -1528,7 +1533,7 @@ impl Display for SemanticError {
15281533
#[cfg(feature = "std")]
15291534
impl std::error::Error for SemanticError { }
15301535

1531-
/// When signing using a fallible method either an user-supplied `SignError` or a `CreationError`
1536+
/// When signing using a fallible method either an user-supplied `SignError` or a [`CreationError`]
15321537
/// may occur.
15331538
#[derive(Eq, PartialEq, Debug, Clone)]
15341539
pub enum SignOrCreationError<S = ()> {

0 commit comments

Comments
 (0)