Skip to content

Commit 1d1c08d

Browse files
committed
Fixes from tnull review
properly link struct and function definitions in `ser_macro.rs` docs
1 parent 71de06e commit 1d1c08d

File tree

1 file changed

+43
-18
lines changed

1 file changed

+43
-18
lines changed

lightning/src/util/ser_macros.rs

Lines changed: 43 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ macro_rules! _check_encoded_tlv_order {
5858
};
5959
}
6060

61-
/// Implements the TLVs serialization part in a Writeable implementation of a struct.
61+
/// Implements the TLVs serialization part in a [`Writeable`] implementation of a struct.
6262
///
6363
/// This should be called inside a method which returns `Result<_, `[`io::Error`]`>`, such as
6464
/// [`Writeable::write`]. It will only return an `Err` if the stream `Err`s or [`Writeable::write`]
@@ -92,6 +92,7 @@ macro_rules! _check_encoded_tlv_order {
9292
/// # }
9393
/// ```
9494
///
95+
/// [`Writeable`]: crate::util::ser::Writeable
9596
/// [`io::Error`]: crate::io::Error
9697
/// [`Writeable::write`]: crate::util::ser::Writeable::write
9798
/// [`Writer`]: crate::util::ser::Writer
@@ -120,8 +121,10 @@ macro_rules! encode_tlv_stream {
120121
} }
121122
}
122123

123-
/// Adds the length of the serialized field to a LengthCalculatingWriter.
124+
/// Adds the length of the serialized field to a [`LengthCalculatingWriter`].
124125
/// This is exported for use by other exported macros, do not use directly.
126+
///
127+
/// [`LengthCalculatingWriter`]: crate::util::ser::LengthCalculatingWriter
125128
#[doc(hidden)]
126129
#[macro_export]
127130
macro_rules! _get_varint_length_prefixed_tlv_length {
@@ -149,7 +152,7 @@ macro_rules! _get_varint_length_prefixed_tlv_length {
149152
};
150153
}
151154

152-
/// See the documentation of write_tlv_fields!().
155+
/// See the documentation of [`write_tlv_fields`].
153156
/// This is exported for use by other exported macros, do not use directly.
154157
#[doc(hidden)]
155158
#[macro_export]
@@ -291,7 +294,7 @@ macro_rules! _decode_tlv_stream_match_check {
291294
($val: ident, $type: expr, $fieldty: tt) => { $val == $type }
292295
}
293296

294-
/// Implements the TLVs deserialization part in a Readable implementation of a struct.
297+
/// Implements the TLVs deserialization part in a [`Readable`] implementation of a struct.
295298
///
296299
/// This should be called inside a method which returns `Result<_, `[`DecodeError`]`>`, such as
297300
/// [`Readable::read`]. It will either return an `Err` or ensure all `required` fields have been
@@ -323,6 +326,7 @@ macro_rules! _decode_tlv_stream_match_check {
323326
/// # }
324327
/// ```
325328
///
329+
/// [`Readable`]: crate::util::ser::Readable
326330
/// [`DecodeError`]: crate::ln::msgs::DecodeError
327331
/// [`Readable::read`]: crate::util::ser::Readable::read
328332
/// [`Read`]: crate::io::Read
@@ -338,9 +342,12 @@ macro_rules! decode_tlv_stream {
338342
/// Similar to [`decode_tlv_stream`] with a custom TLV decoding capabilities.
339343
///
340344
/// `$decode_custom_tlv` is a closure that may be optionally provided to handle custom message types.
341-
/// If it is provided, it will be called with the custom type and the `FixedLengthReader` containing
345+
/// If it is provided, it will be called with the custom type and the [`FixedLengthReader`] containing
342346
/// the message contents. It should return `Ok(true)` if the custom message is successfully parsed,
343-
/// `Ok(false)` if the message type is unknown, and `Err(DecodeError)` if parsing fails.
347+
/// `Ok(false)` if the message type is unknown, and `Err(`[`DecodeError`]`)` if parsing fails.
348+
///
349+
/// [`FixedLengthReader`]: crate::util::ser::FixedLengthReader
350+
/// [`DecodeError`]: crate::ln::msgs::DecodeError
344351
macro_rules! decode_tlv_stream_with_custom_tlv_decode {
345352
($stream: expr, {$(($type: expr, $field: ident, $fieldty: tt)),* $(,)*}
346353
$(, $decode_custom_tlv: expr)?) => { {
@@ -494,12 +501,14 @@ macro_rules! impl_writeable {
494501
/// object.
495502
/// $min_version_that_can_read_this is the minimum reader version which can understand this
496503
/// serialized object. Previous versions will simply err with a
497-
/// DecodeError::UnknownVersion.
504+
/// [`DecodeError::UnknownVersion`].
498505
///
499506
/// Updates to either $this_version or $min_version_that_can_read_this should be included in
500507
/// release notes.
501508
///
502509
/// Both version fields can be specific to this type of object.
510+
///
511+
/// [`DecodeError::UnknownVersion`]: crate::ln::msgs::DecodeError::UnknownVersion
503512
macro_rules! write_ver_prefix {
504513
($stream: expr, $this_version: expr, $min_version_that_can_read_this: expr) => {
505514
$stream.write_all(&[$this_version; 1])?;
@@ -511,20 +520,22 @@ macro_rules! write_ver_prefix {
511520
/// fields which old nodes can happily ignore.
512521
///
513522
/// It is written out in TLV format and, as with all TLV fields, unknown even fields cause a
514-
/// DecodeError::UnknownRequiredFeature error, with unknown odd fields ignored.
523+
/// [`DecodeError::UnknownRequiredFeature`] error, with unknown odd fields ignored.
515524
///
516525
/// This is the preferred method of adding new fields that old nodes can ignore and still function
517526
/// correctly.
527+
///
528+
/// [`DecodeError::UnknownRequiredFeature`]: crate::ln::msgs::DecodeError::UnknownRequiredFeature
518529
#[macro_export]
519530
macro_rules! write_tlv_fields {
520531
($stream: expr, {$(($type: expr, $field: expr, $fieldty: tt)),* $(,)*}) => {
521532
$crate::_encode_varint_length_prefixed_tlv!($stream, {$(($type, $field, $fieldty)),*})
522533
}
523534
}
524535

525-
/// Reads a prefix added by write_ver_prefix!(), above. Takes the current version of the
536+
/// Reads a prefix added by [`write_ver_prefix`], above. Takes the current version of the
526537
/// serialization logic for this object. This is compared against the
527-
/// $min_version_that_can_read_this added by write_ver_prefix!().
538+
/// $min_version_that_can_read_this added by [`write_ver_prefix`].
528539
macro_rules! read_ver_prefix {
529540
($stream: expr, $this_version: expr) => { {
530541
let ver: u8 = Readable::read($stream)?;
@@ -536,7 +547,9 @@ macro_rules! read_ver_prefix {
536547
} }
537548
}
538549

539-
/// Reads a suffix added by write_tlv_fields!().
550+
/// Reads a suffix added by [`write_tlv_fields`].
551+
///
552+
/// [`write_tlv_fields`]: crate::write_tlv_fields
540553
#[macro_export]
541554
macro_rules! read_tlv_fields {
542555
($stream: expr, {$(($type: expr, $field: ident, $fieldty: tt)),* $(,)*}) => { {
@@ -606,11 +619,14 @@ macro_rules! _init_and_read_tlv_fields {
606619
}
607620
}
608621

609-
/// Implements Readable/Writeable for a struct storing it as a set of TLVs
622+
/// Implements [`Readable`]/[`Writeable`] for a struct storing it as a set of TLVs
610623
/// If $fieldty is `required`, then $field is a required field that is not an Option nor a Vec.
611624
/// If $fieldty is `option`, then $field is optional field.
612625
/// if $fieldty is `vec_type`, then $field is a Vec, which needs to have its individual elements
613626
/// serialized.
627+
///
628+
/// [`Readable`]: crate::util::ser::Readable
629+
/// [`Writeable`]: crate::util::ser::Writeable
614630
#[macro_export]
615631
macro_rules! impl_writeable_tlv_based {
616632
($st: ident, {$(($type: expr, $field: ident, $fieldty: tt)),* $(,)*}) => {
@@ -754,13 +770,18 @@ macro_rules! _impl_writeable_tlv_based_enum_common {
754770
}
755771
}
756772

757-
/// Implement MaybeReadable and Writeable for an enum, with struct variants stored as TLVs and
773+
/// Implement [`MaybeReadable`] and [`Writeable`] for an enum, with struct variants stored as TLVs and
758774
/// tuple variants stored directly.
759775
///
760-
/// This is largely identical to `impl_writeable_tlv_based_enum`, except that odd variants will
761-
/// return `Ok(None)` instead of `Err(UnknownRequiredFeature)`. It should generally be preferred
762-
/// when `MaybeReadable` is practical instead of just `Readable` as it provides an upgrade path for
776+
/// This is largely identical to [`impl_writeable_tlv_based_enum`], except that odd variants will
777+
/// return `Ok(None)` instead of `Err(`[`DecodeError::UnknownRequiredFeature`]`)`. It should generally be preferred
778+
/// when [`MaybeReadable`] is practical instead of just [`Readable`] as it provides an upgrade path for
763779
/// new variants to be added which are simply ignored by existing clients.
780+
///
781+
/// [`MaybeReadable`]: crate::util::ser::MaybeReadable
782+
/// [`Writeable`]: crate::util::ser::Writeable
783+
/// [`DecodeError::UnknownRequiredFeature`]: crate::ln::msgs::DecodeError::UnknownRequiredFeature
784+
/// [`Readable`]: crate::util::ser::Readable
764785
macro_rules! impl_writeable_tlv_based_enum_upgradable {
765786
($st: ident, $(($variant_id: expr, $variant_name: ident) =>
766787
{$(($type: expr, $field: ident, $fieldty: tt)),* $(,)*}
@@ -802,7 +823,7 @@ macro_rules! impl_writeable_tlv_based_enum_upgradable {
802823
}
803824
}
804825

805-
/// Implement Readable and Writeable for an enum, with struct variants stored as TLVs and tuple
826+
/// Implement [`Readable`] and [`Writeable`] for an enum, with struct variants stored as TLVs and tuple
806827
/// variants stored directly.
807828
/// The format is, for example
808829
/// impl_writeable_tlv_based_enum!(EnumName,
@@ -811,7 +832,11 @@ macro_rules! impl_writeable_tlv_based_enum_upgradable {
811832
/// (2, TupleVariantA), (3, TupleVariantB),
812833
/// );
813834
/// The type is written as a single byte, followed by any variant data.
814-
/// Attempts to read an unknown type byte result in DecodeError::UnknownRequiredFeature.
835+
/// Attempts to read an unknown type byte result in [`DecodeError::UnknownRequiredFeature`].
836+
///
837+
/// [`Readable`]: crate::util::ser::Readable
838+
/// [`Writeable`]: crate::util::ser::Writeable
839+
/// [`DecodeError::UnknownRequiredFeature`]: crate::ln::msgs::DecodeError::UnknownRequiredFeature
815840
macro_rules! impl_writeable_tlv_based_enum {
816841
($st: ident, $(($variant_id: expr, $variant_name: ident) =>
817842
{$(($type: expr, $field: ident, $fieldty: tt)),* $(,)*}

0 commit comments

Comments
 (0)