Skip to content

Commit b5bdfa9

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

File tree

1 file changed

+41
-18
lines changed

1 file changed

+41
-18
lines changed

lightning/src/util/ser_macros.rs

+41-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,7 @@ 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`].
510521
#[macro_export]
511522
macro_rules! read_tlv_fields {
512523
($stream: expr, {$(($type: expr, $field: ident, $fieldty: tt)),* $(,)*}) => { {
@@ -570,11 +581,14 @@ macro_rules! _init_and_read_tlv_fields {
570581
}
571582
}
572583

573-
/// Implements Readable/Writeable for a struct storing it as a set of TLVs
584+
/// Implements [`Readable`]/[`Writeable`] for a struct storing it as a set of TLVs
574585
/// If $fieldty is `required`, then $field is a required field that is not an Option nor a Vec.
575586
/// If $fieldty is `option`, then $field is optional field.
576587
/// if $fieldty is `vec_type`, then $field is a Vec, which needs to have its individual elements
577588
/// serialized.
589+
///
590+
/// [`Readable`]: crate::util::ser::Readable
591+
/// [`Writeable`]: crate::util::ser::Writeable
578592
#[macro_export]
579593
macro_rules! impl_writeable_tlv_based {
580594
($st: ident, {$(($type: expr, $field: ident, $fieldty: tt)),* $(,)*}) => {
@@ -717,13 +731,18 @@ macro_rules! _impl_writeable_tlv_based_enum_common {
717731
}
718732
}
719733

720-
/// Implement MaybeReadable and Writeable for an enum, with struct variants stored as TLVs and
734+
/// Implement [`MaybeReadable`] and [`Writeable`] for an enum, with struct variants stored as TLVs and
721735
/// tuple variants stored directly.
722736
///
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
737+
/// This is largely identical to [`impl_writeable_tlv_based_enum`], except that odd variants will
738+
/// return `Ok(None)` instead of `Err(`[`DecodeError::UnknownRequiredFeature`]`)`. It should generally be preferred
739+
/// when [`MaybeReadable`] is practical instead of just [`Readable`] as it provides an upgrade path for
726740
/// new variants to be added which are simply ignored by existing clients.
741+
///
742+
/// [`MaybeReadable`]: crate::util::ser::MaybeReadable
743+
/// [`Writeable`]: crate::util::ser::Writeable
744+
/// [`DecodeError::UnknownRequiredFeature`]: crate::ln::msgs::DecodeError::UnknownRequiredFeature
745+
/// [`Readable`]: crate::util::ser::Readable
727746
macro_rules! impl_writeable_tlv_based_enum_upgradable {
728747
($st: ident, $(($variant_id: expr, $variant_name: ident) =>
729748
{$(($type: expr, $field: ident, $fieldty: tt)),* $(,)*}
@@ -765,7 +784,7 @@ macro_rules! impl_writeable_tlv_based_enum_upgradable {
765784
}
766785
}
767786

768-
/// Implement Readable and Writeable for an enum, with struct variants stored as TLVs and tuple
787+
/// Implement [`Readable`] and [`Writeable`] for an enum, with struct variants stored as TLVs and tuple
769788
/// variants stored directly.
770789
/// The format is, for example
771790
/// impl_writeable_tlv_based_enum!(EnumName,
@@ -774,7 +793,11 @@ macro_rules! impl_writeable_tlv_based_enum_upgradable {
774793
/// (2, TupleVariantA), (3, TupleVariantB),
775794
/// );
776795
/// 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.
796+
/// Attempts to read an unknown type byte result in [`DecodeError::UnknownRequiredFeature`].
797+
///
798+
/// [`Readable`]: crate::util::ser::Readable
799+
/// [`Writeable`]: crate::util::ser::Writeable
800+
/// [`DecodeError::UnknownRequiredFeature`]: crate::ln::msgs::DecodeError::UnknownRequiredFeature
778801
macro_rules! impl_writeable_tlv_based_enum {
779802
($st: ident, $(($variant_id: expr, $variant_name: ident) =>
780803
{$(($type: expr, $field: ident, $fieldty: tt)),* $(,)*}

0 commit comments

Comments
 (0)