Skip to content

Commit 32b419c

Browse files
committed
Fixes from tnull review
properly link struct and function definitions in `ser_macro.rs` docs
1 parent 195c206 commit 32b419c

File tree

1 file changed

+43
-18
lines changed

1 file changed

+43
-18
lines changed

lightning/src/util/ser_macros.rs

+43-18
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ macro_rules! _encode_tlv {
4141
};
4242
}
4343

44-
/// Implements the TLVs serialization part in a Writeable implementation of a struct.
44+
/// Implements the TLVs serialization part in a [`Writeable`] implementation of a struct.
4545
///
4646
/// This should be called inside a method which returns `Result<_, `[`io::Error`]`>`, such as
4747
/// [`Writeable::write`]. It will only return an `Err` if the stream `Err`s or [`Writeable::write`]
@@ -75,6 +75,7 @@ macro_rules! _encode_tlv {
7575
/// # }
7676
/// ```
7777
///
78+
/// [`Writeable`]: crate::util::ser::Writeable
7879
/// [`io::Error`]: crate::io::Error
7980
/// [`Writeable::write`]: crate::util::ser::Writeable::write
8081
/// [`Writer`]: crate::util::ser::Writer
@@ -107,8 +108,10 @@ macro_rules! encode_tlv_stream {
107108
} }
108109
}
109110

110-
/// Adds the length of the serialized field to a LengthCalculatingWriter.
111+
/// Adds the length of the serialized field to a [`LengthCalculatingWriter`].
111112
/// This is exported for use by other exported macros, do not use directly.
113+
///
114+
/// [`LengthCalculatingWriter`]: crate::util::ser::LengthCalculatingWriter
112115
#[doc(hidden)]
113116
#[macro_export]
114117
macro_rules! _get_varint_length_prefixed_tlv_length {
@@ -134,7 +137,7 @@ macro_rules! _get_varint_length_prefixed_tlv_length {
134137
};
135138
}
136139

137-
/// See the documentation of write_tlv_fields!().
140+
/// See the documentation of [`write_tlv_fields`].
138141
/// This is exported for use by other exported macros, do not use directly.
139142
#[doc(hidden)]
140143
#[macro_export]
@@ -261,7 +264,7 @@ macro_rules! _decode_tlv {
261264
}};
262265
}
263266

264-
/// Implements the TLVs deserialization part in a Readable implementation of a struct.
267+
/// Implements the TLVs deserialization part in a [`Readable`] implementation of a struct.
265268
///
266269
/// This should be called inside a method which returns `Result<_, `[`DecodeError`]`>`, such as
267270
/// [`Readable::read`]. It will either return an `Err` or ensure all `required` fields have been
@@ -293,6 +296,7 @@ macro_rules! _decode_tlv {
293296
/// # }
294297
/// ```
295298
///
299+
/// [`Readable`]: crate::util::ser::Readable
296300
/// [`DecodeError`]: crate::ln::msgs::DecodeError
297301
/// [`Readable::read`]: crate::util::ser::Readable::read
298302
/// [`Read`]: crate::io::Read
@@ -308,9 +312,12 @@ macro_rules! decode_tlv_stream {
308312
/// Similar to [`decode_tlv_stream`] with a custom TLV decoding capabilities.
309313
///
310314
/// `$decode_custom_tlv` is a closure that may be optionally provided to handle custom message types.
311-
/// If it is provided, it will be called with the custom type and the `FixedLengthReader` containing
315+
/// If it is provided, it will be called with the custom type and the [`FixedLengthReader`] containing
312316
/// the message contents. It should return `Ok(true)` if the custom message is successfully parsed,
313-
/// `Ok(false)` if the message type is unknown, and `Err(DecodeError)` if parsing fails.
317+
/// `Ok(false)` if the message type is unknown, and `Err(`[`DecodeError`]`)` if parsing fails.
318+
///
319+
/// [`FixedLengthReader`]: crate::util::ser::FixedLengthReader
320+
/// [`DecodeError`]: crate::ln::msgs::DecodeError
314321
macro_rules! decode_tlv_stream_with_custom_tlv_decode {
315322
($stream: expr, {$(($type: expr, $field: ident, $fieldty: tt)),* $(,)*}
316323
$(, $decode_custom_tlv: expr)?) => { {
@@ -464,12 +471,14 @@ macro_rules! impl_writeable {
464471
/// object.
465472
/// $min_version_that_can_read_this is the minimum reader version which can understand this
466473
/// serialized object. Previous versions will simply err with a
467-
/// DecodeError::UnknownVersion.
474+
/// [`DecodeError::UnknownVersion`].
468475
///
469476
/// Updates to either $this_version or $min_version_that_can_read_this should be included in
470477
/// release notes.
471478
///
472479
/// Both version fields can be specific to this type of object.
480+
///
481+
/// [`DecodeError::UnknownVersion`]: crate::ln::msgs::DecodeError::UnknownVersion
473482
macro_rules! write_ver_prefix {
474483
($stream: expr, $this_version: expr, $min_version_that_can_read_this: expr) => {
475484
$stream.write_all(&[$this_version; 1])?;
@@ -481,20 +490,22 @@ macro_rules! write_ver_prefix {
481490
/// fields which old nodes can happily ignore.
482491
///
483492
/// It is written out in TLV format and, as with all TLV fields, unknown even fields cause a
484-
/// DecodeError::UnknownRequiredFeature error, with unknown odd fields ignored.
493+
/// [`DecodeError::UnknownRequiredFeature`] error, with unknown odd fields ignored.
485494
///
486495
/// This is the preferred method of adding new fields that old nodes can ignore and still function
487496
/// correctly.
497+
///
498+
/// [`DecodeError::UnknownRequiredFeature`]: crate::ln::msgs::DecodeError::UnknownRequiredFeature
488499
#[macro_export]
489500
macro_rules! write_tlv_fields {
490501
($stream: expr, {$(($type: expr, $field: expr, $fieldty: tt)),* $(,)*}) => {
491502
$crate::_encode_varint_length_prefixed_tlv!($stream, {$(($type, $field, $fieldty)),*})
492503
}
493504
}
494505

495-
/// Reads a prefix added by write_ver_prefix!(), above. Takes the current version of the
506+
/// Reads a prefix added by [`write_ver_prefix`], above. Takes the current version of the
496507
/// serialization logic for this object. This is compared against the
497-
/// $min_version_that_can_read_this added by write_ver_prefix!().
508+
/// $min_version_that_can_read_this added by [`write_ver_prefix`].
498509
macro_rules! read_ver_prefix {
499510
($stream: expr, $this_version: expr) => { {
500511
let ver: u8 = Readable::read($stream)?;
@@ -506,7 +517,9 @@ macro_rules! read_ver_prefix {
506517
} }
507518
}
508519

509-
/// Reads a suffix added by write_tlv_fields!().
520+
/// Reads a suffix added by [`write_tlv_fields`].
521+
///
522+
/// [`write_tlv_fields`]: crate::write_tlv_fields
510523
#[macro_export]
511524
macro_rules! read_tlv_fields {
512525
($stream: expr, {$(($type: expr, $field: ident, $fieldty: tt)),* $(,)*}) => { {
@@ -570,11 +583,14 @@ macro_rules! _init_and_read_tlv_fields {
570583
}
571584
}
572585

573-
/// Implements Readable/Writeable for a struct storing it as a set of TLVs
586+
/// Implements [`Readable`]/[`Writeable`] for a struct storing it as a set of TLVs
574587
/// If $fieldty is `required`, then $field is a required field that is not an Option nor a Vec.
575588
/// If $fieldty is `option`, then $field is optional field.
576589
/// if $fieldty is `vec_type`, then $field is a Vec, which needs to have its individual elements
577590
/// serialized.
591+
///
592+
/// [`Readable`]: crate::util::ser::Readable
593+
/// [`Writeable`]: crate::util::ser::Writeable
578594
#[macro_export]
579595
macro_rules! impl_writeable_tlv_based {
580596
($st: ident, {$(($type: expr, $field: ident, $fieldty: tt)),* $(,)*}) => {
@@ -717,13 +733,18 @@ macro_rules! _impl_writeable_tlv_based_enum_common {
717733
}
718734
}
719735

720-
/// Implement MaybeReadable and Writeable for an enum, with struct variants stored as TLVs and
736+
/// Implement [`MaybeReadable`] and [`Writeable`] for an enum, with struct variants stored as TLVs and
721737
/// tuple variants stored directly.
722738
///
723-
/// This is largely identical to `impl_writeable_tlv_based_enum`, except that odd variants will
724-
/// return `Ok(None)` instead of `Err(UnknownRequiredFeature)`. It should generally be preferred
725-
/// when `MaybeReadable` is practical instead of just `Readable` as it provides an upgrade path for
739+
/// This is largely identical to [`impl_writeable_tlv_based_enum`], except that odd variants will
740+
/// return `Ok(None)` instead of `Err(`[`DecodeError::UnknownRequiredFeature`]`)`. It should generally be preferred
741+
/// when [`MaybeReadable`] is practical instead of just [`Readable`] as it provides an upgrade path for
726742
/// new variants to be added which are simply ignored by existing clients.
743+
///
744+
/// [`MaybeReadable`]: crate::util::ser::MaybeReadable
745+
/// [`Writeable`]: crate::util::ser::Writeable
746+
/// [`DecodeError::UnknownRequiredFeature`]: crate::ln::msgs::DecodeError::UnknownRequiredFeature
747+
/// [`Readable`]: crate::util::ser::Readable
727748
macro_rules! impl_writeable_tlv_based_enum_upgradable {
728749
($st: ident, $(($variant_id: expr, $variant_name: ident) =>
729750
{$(($type: expr, $field: ident, $fieldty: tt)),* $(,)*}
@@ -765,7 +786,7 @@ macro_rules! impl_writeable_tlv_based_enum_upgradable {
765786
}
766787
}
767788

768-
/// Implement Readable and Writeable for an enum, with struct variants stored as TLVs and tuple
789+
/// Implement [`Readable`] and [`Writeable`] for an enum, with struct variants stored as TLVs and tuple
769790
/// variants stored directly.
770791
/// The format is, for example
771792
/// impl_writeable_tlv_based_enum!(EnumName,
@@ -774,7 +795,11 @@ macro_rules! impl_writeable_tlv_based_enum_upgradable {
774795
/// (2, TupleVariantA), (3, TupleVariantB),
775796
/// );
776797
/// The type is written as a single byte, followed by any variant data.
777-
/// Attempts to read an unknown type byte result in DecodeError::UnknownRequiredFeature.
798+
/// Attempts to read an unknown type byte result in [`DecodeError::UnknownRequiredFeature`].
799+
///
800+
/// [`Readable`]: crate::util::ser::Readable
801+
/// [`Writeable`]: crate::util::ser::Writeable
802+
/// [`DecodeError::UnknownRequiredFeature`]: crate::ln::msgs::DecodeError::UnknownRequiredFeature
778803
macro_rules! impl_writeable_tlv_based_enum {
779804
($st: ident, $(($variant_id: expr, $variant_name: ident) =>
780805
{$(($type: expr, $field: ident, $fieldty: tt)),* $(,)*}

0 commit comments

Comments
 (0)