]> git.bitcoin.ninja Git - ldk-c-bindings/commitdiff
Support mapping `Readable` `impl`s outside of the `lightning` crate
authorMatt Corallo <git@bluematt.me>
Mon, 19 Sep 2022 10:16:38 +0000 (10:16 +0000)
committerMatt Corallo <git@bluematt.me>
Fri, 23 Sep 2022 16:16:26 +0000 (16:16 +0000)
In order to map `Readable` `impl` blocks in crates other than the
`lightning` main crate we simply have to update the type references
to include crate name, which we do here.

c-bindings-gen/src/main.rs

index fd32a1ca776610dd5813d7f6dc2fce41b6e5bb72..9c11cf374f1f2956205b6fe37dd4551b0f4908e8 100644 (file)
@@ -102,7 +102,7 @@ fn maybe_convert_trait_impl<W: std::io::Write>(w: &mut W, trait_path: &syn::Path
                        },
                        "lightning::util::ser::Readable"|"lightning::util::ser::ReadableArgs"|"lightning::util::ser::MaybeReadable" => {
                                // Create the Result<Object, DecodeError> syn::Type
-                               let mut res_ty: syn::Type = parse_quote!(Result<#for_ty, ::ln::msgs::DecodeError>);
+                               let mut res_ty: syn::Type = parse_quote!(Result<#for_ty, lightning::ln::msgs::DecodeError>);
 
                                writeln!(w, "#[no_mangle]").unwrap();
                                writeln!(w, "/// Read a {} from a byte array, created by {}_write", for_obj, for_obj).unwrap();
@@ -151,7 +151,7 @@ fn maybe_convert_trait_impl<W: std::io::Write>(w: &mut W, trait_path: &syn::Path
                                                } else { unreachable!(); }
                                        } else { unreachable!(); }
                                } else if t == "lightning::util::ser::MaybeReadable" {
-                                       res_ty = parse_quote!(Result<Option<#for_ty>, ::ln::msgs::DecodeError>);
+                                       res_ty = parse_quote!(Result<Option<#for_ty>, lightning::ln::msgs::DecodeError>);
                                }
                                write!(w, ") -> ").unwrap();
                                types.write_c_type(w, &res_ty, Some(generics), false);