Skip to content

Commit

Permalink
f misc fixes and better macro docs
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBlueMatt committed Dec 8, 2024
1 parent e3d3db4 commit f1a7bec
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
19 changes: 15 additions & 4 deletions lightning-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,22 +238,33 @@ pub fn skip_legacy_fields(expr: TokenStream) -> TokenStream {
res
}

/// Scans an enum definition for fields initialized to `LDK_DROP_LEGACY_FIELD_DEFINITION` and drops
/// that field.
/// Scans an enum definition for fields initialized with `legacy` types and drops them.
///
/// This is used internally in LDK's TLV serialization logic and is not expected to be used by
/// other crates.
///
/// Is expected to wrap a struct definition like
/// ```ignore
/// drop_legacy_field_definition!(Self {
/// field1: _init_tlv_based_struct_field!(field1, option),
/// field2: _init_tlv_based_struct_field!(field2, (legacy, u64, {}, {}))),
/// })
/// ```
/// and will drop fields defined like `field2` with a type starting with `legacy`.
#[proc_macro]
pub fn drop_legacy_field_definition(expr: TokenStream) -> TokenStream {
let mut st = if let Ok(parsed) = parse::<syn::Expr>(expr) {
if let syn::Expr::Struct(st) = parsed {
st
} else {
return (quote! {
compile_error!("drop_legacy_field_definitions!() can only be used on struct expressions")
compile_error!("drop_legacy_field_definition!() can only be used on struct expressions")
})
.into();
}
} else {
return (quote! {
compile_error!("drop_legacy_field_definitions!() can only be used on expressions")
compile_error!("drop_legacy_field_definition!() can only be used on expressions")
})
.into();
};
Expand Down
1 change: 0 additions & 1 deletion lightning/src/util/ser_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,6 @@ macro_rules! _run_legacy_tlv_read_logic {
($field: ident, $fieldty: tt) => { }
}


/// Checks if `$val` matches `$type`.
/// This is exported for use by other exported macros, do not use directly.
#[doc(hidden)]
Expand Down

0 comments on commit f1a7bec

Please sign in to comment.