Include argument info docs on all-pub struct constructors
authorMatt Corallo <git@bluematt.me>
Sun, 1 Oct 2023 23:05:26 +0000 (23:05 +0000)
committerMatt Corallo <git@bluematt.me>
Wed, 4 Oct 2023 20:02:23 +0000 (20:02 +0000)
Fixes https://github.com/lightningdevkit/ldk-garbagecollected/issues/129

c-bindings-gen/src/main.rs

index 956420be780a938e817d856392f928b443695257..7c066875a5b6a0198e8dadf2ecdaa7d6e725831e 100644 (file)
@@ -812,6 +812,19 @@ fn writeln_struct<'a, 'b, W: std::io::Write>(w: &mut W, s: &'a syn::ItemStruct,
        if all_fields_settable {
                // Build a constructor!
                writeln!(w, "/// Constructs a new {} given each field", struct_name).unwrap();
+               match &s.fields {
+                       syn::Fields::Named(fields) => {
+                               writeln_arg_docs(w, &[], "", types, Some(&gen_types),
+                                       fields.named.iter().map(|field| (format!("{}_arg", field.ident.as_ref().unwrap()), &field.ty)),
+                                       None);
+                       },
+                       syn::Fields::Unnamed(fields) => {
+                               writeln_arg_docs(w, &[], "", types, Some(&gen_types),
+                                       fields.unnamed.iter().enumerate().map(|(idx, field)| (format!("{}_arg", ('a' as u8 + idx as u8)), &field.ty)),
+                                       None);
+                       },
+                       syn::Fields::Unit => {},
+               }
                write!(w, "#[must_use]\n#[no_mangle]\npub extern \"C\" fn {}_new(", struct_name).unwrap();
 
                match &s.fields {