Skip to content

Expose _impl_writeable_tlv_based_enum_common macro #2091

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions lightning/src/util/ser_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,8 @@ macro_rules! tlv_record_ref_type {
($type:ty) => { &'a $type };
}

#[doc(hidden)]
#[macro_export]
macro_rules! _impl_writeable_tlv_based_enum_common {
($st: ident, $(($variant_id: expr, $variant_name: ident) =>
{$(($type: expr, $field: ident, $fieldty: tt)),* $(,)*}
Expand All @@ -885,7 +887,7 @@ macro_rules! _impl_writeable_tlv_based_enum_common {
$($st::$variant_name { $(ref $field),* } => {
let id: u8 = $variant_id;
id.write(writer)?;
write_tlv_fields!(writer, {
$crate::write_tlv_fields!(writer, {
$(($type, *$field, $fieldty)),*
});
}),*
Expand Down Expand Up @@ -923,7 +925,7 @@ macro_rules! impl_writeable_tlv_based_enum {
{$(($type: expr, $field: ident, $fieldty: tt)),* $(,)*}
),* $(,)*;
$(($tuple_variant_id: expr, $tuple_variant_name: ident)),* $(,)*) => {
_impl_writeable_tlv_based_enum_common!($st,
$crate::_impl_writeable_tlv_based_enum_common!($st,
$(($variant_id, $variant_name) => {$(($type, $field, $fieldty)),*}),*;
$(($tuple_variant_id, $tuple_variant_name)),*);

Expand All @@ -935,12 +937,12 @@ macro_rules! impl_writeable_tlv_based_enum {
// Because read_tlv_fields creates a labeled loop, we cannot call it twice
// in the same function body. Instead, we define a closure and call it.
let f = || {
_init_and_read_tlv_fields!(reader, {
$crate::_init_and_read_tlv_fields!(reader, {
$(($type, $field, $fieldty)),*
});
Ok($st::$variant_name {
$(
$field: _init_tlv_based_struct_field!($field, $fieldty)
$field: $crate::_init_tlv_based_struct_field!($field, $fieldty)
),*
})
};
Expand Down Expand Up @@ -977,7 +979,7 @@ macro_rules! impl_writeable_tlv_based_enum_upgradable {
),* $(,)*
$(;
$(($tuple_variant_id: expr, $tuple_variant_name: ident)),* $(,)*)*) => {
_impl_writeable_tlv_based_enum_common!($st,
$crate::_impl_writeable_tlv_based_enum_common!($st,
$(($variant_id, $variant_name) => {$(($type, $field, $fieldty)),*}),*;
$($(($tuple_variant_id, $tuple_variant_name)),*)*);

Expand All @@ -989,12 +991,12 @@ macro_rules! impl_writeable_tlv_based_enum_upgradable {
// Because read_tlv_fields creates a labeled loop, we cannot call it twice
// in the same function body. Instead, we define a closure and call it.
let f = || {
_init_and_read_tlv_fields!(reader, {
$crate::_init_and_read_tlv_fields!(reader, {
$(($type, $field, $fieldty)),*
});
Ok(Some($st::$variant_name {
$(
$field: _init_tlv_based_struct_field!($field, $fieldty)
$field: $crate::_init_tlv_based_struct_field!($field, $fieldty)
),*
}))
};
Expand Down