Update auto-generated bindings to include ln-transaction-sync
[ldk-c-bindings] / c-bindings-gen / src / main.rs
index 4572f7d921d405256d67b50d7616cacf8461aa7f..26c63704118ac84fc9cebf5f2779b57477b19ed1 100644 (file)
@@ -1185,28 +1185,29 @@ fn writeln_impl<W: std::io::Write>(w: &mut W, w_uses: &mut HashSet<String, NonRa
                                                                        write_method_var_decl_body(w, &$trait_meth.sig, "", &mut trait_resolver, Some(&meth_gen_types), false);
                                                                        let mut takes_self = false;
                                                                        for inp in $m.sig.inputs.iter() {
                                                                        write_method_var_decl_body(w, &$trait_meth.sig, "", &mut trait_resolver, Some(&meth_gen_types), false);
                                                                        let mut takes_self = false;
                                                                        for inp in $m.sig.inputs.iter() {
-                                                                               if let syn::FnArg::Receiver(_) = inp {
-                                                                                       takes_self = true;
+                                                                               match inp {
+                                                                                       syn::FnArg::Receiver(_) => {
+                                                                                               takes_self = true;
+                                                                                               break;
+                                                                                       },
+                                                                                       syn::FnArg::Typed(ty) => {
+                                                                                               if let syn::Pat::Ident(id) = &*ty.pat {
+                                                                                                       if format!("{}", id.ident) == "self" {
+                                                                                                               takes_self = true;
+                                                                                                               break;
+                                                                                                       }
+                                                                                               }
+                                                                                       }
                                                                                }
                                                                        }
 
                                                                                }
                                                                        }
 
-                                                                       let mut t_gen_args = String::new();
-                                                                       for (idx, _) in $trait.generics.params.iter().enumerate() {
-                                                                               if idx != 0 { t_gen_args += ", " };
-                                                                               t_gen_args += "_"
-                                                                       }
-                                                                       // rustc doesn't like <_> if the _ is actually a lifetime, so
-                                                                       // if all the parameters are lifetimes just skip it.
-                                                                       let mut nonlifetime_param = false;
-                                                                       for param in $trait.generics.params.iter() {
-                                                                               if let syn::GenericParam::Lifetime(_) = param {}
-                                                                               else { nonlifetime_param = true; }
-                                                                       }
-                                                                       if !nonlifetime_param { t_gen_args = String::new(); }
+                                                                       let mut t_gen_args_vec = Vec::new();
+                                                                       maybe_write_type_non_lifetime_generics(&mut t_gen_args_vec, &$trait.generics, &trait_resolver);
+                                                                       let t_gen_args = String::from_utf8(t_gen_args_vec).unwrap();
                                                                        if takes_self {
                                                                        if takes_self {
-                                                                               write!(w, "<native{} as {}<{}>>::{}(unsafe {{ &mut *(this_arg as *mut native{}) }}, ", ident, $trait_path, t_gen_args, $m.sig.ident, ident).unwrap();
+                                                                               write!(w, "<native{} as {}{}>::{}(unsafe {{ &mut *(this_arg as *mut native{}) }}, ", ident, $trait_path, t_gen_args, $m.sig.ident, ident).unwrap();
                                                                        } else {
                                                                        } else {
-                                                                               write!(w, "<native{} as {}<{}>>::{}(", ident, $trait_path, t_gen_args, $m.sig.ident).unwrap();
+                                                                               write!(w, "<native{} as {}{}>::{}(", ident, $trait_path, t_gen_args, $m.sig.ident).unwrap();
                                                                        }
 
                                                                        let mut real_type = "".to_string();
                                                                        }
 
                                                                        let mut real_type = "".to_string();
@@ -1407,7 +1408,9 @@ fn writeln_impl<W: std::io::Write>(w: &mut W, w_uses: &mut HashSet<String, NonRa
 
                                                write!(w, "\talloc::format!(\"{{:?}}\", unsafe {{ o as *const crate::{} }}).into()", resolved_path).unwrap();
                                                writeln!(w, "}}").unwrap();
 
                                                write!(w, "\talloc::format!(\"{{:?}}\", unsafe {{ o as *const crate::{} }}).into()", resolved_path).unwrap();
                                                writeln!(w, "}}").unwrap();
-                                       } else if path_matches_nongeneric(&trait_path.1, &["Display"]) {
+                                       } else if full_trait_path_opt.as_ref().map(|s| s.as_str()) == Some("core::fmt::Display") ||
+                                               path_matches_nongeneric(&trait_path.1, &["Display"])
+                                       {
                                                writeln!(w, "#[no_mangle]").unwrap();
                                                writeln!(w, "/// Get the string representation of a {} object", ident).unwrap();
                                                writeln!(w, "pub extern \"C\" fn {}_to_str(o: &crate::{}) -> Str {{", ident, resolved_path).unwrap();
                                                writeln!(w, "#[no_mangle]").unwrap();
                                                writeln!(w, "/// Get the string representation of a {} object", ident).unwrap();
                                                writeln!(w, "pub extern \"C\" fn {}_to_str(o: &crate::{}) -> Str {{", ident, resolved_path).unwrap();
@@ -1456,10 +1459,23 @@ fn writeln_impl<W: std::io::Write>(w: &mut W, w_uses: &mut HashSet<String, NonRa
                                                                        let mut takes_mut_self = false;
                                                                        let mut takes_owned_self = false;
                                                                        for inp in m.sig.inputs.iter() {
                                                                        let mut takes_mut_self = false;
                                                                        let mut takes_owned_self = false;
                                                                        for inp in m.sig.inputs.iter() {
-                                                                               if let syn::FnArg::Receiver(r) = inp {
-                                                                                       takes_self = true;
-                                                                                       if r.mutability.is_some() { takes_mut_self = true; }
-                                                                                       if r.reference.is_none() { takes_owned_self = true; }
+                                                                               match inp {
+                                                                                       syn::FnArg::Receiver(r) => {
+                                                                                               takes_self = true;
+                                                                                               if r.mutability.is_some() { takes_mut_self = true; }
+                                                                                               if r.reference.is_none() { takes_owned_self = true; }
+                                                                                               break;
+                                                                                       },
+                                                                                       syn::FnArg::Typed(ty) => {
+                                                                                               if let syn::Pat::Ident(id) = &*ty.pat {
+                                                                                                       if format!("{}", id.ident) == "self" {
+                                                                                                               takes_self = true;
+                                                                                                               if id.mutability.is_some() { takes_mut_self = true; }
+                                                                                                               if id.by_ref.is_none() { takes_owned_self = true; }
+                                                                                                               break;
+                                                                                                       }
+                                                                                               }
+                                                                                       }
                                                                                }
                                                                        }
                                                                        if !takes_mut_self && !takes_self {
                                                                                }
                                                                        }
                                                                        if !takes_mut_self && !takes_self {
@@ -2086,9 +2102,7 @@ fn convert_file<'a, 'b>(libast: &'a FullLibraryAST, crate_types: &CrateTypes<'a>
                        // TODO: We need to map deny(missing_docs) in the source crate(s)
                        //writeln!(out, "#![deny(missing_docs)]").unwrap();
 
                        // TODO: We need to map deny(missing_docs) in the source crate(s)
                        //writeln!(out, "#![deny(missing_docs)]").unwrap();
 
-                       writeln!(out, "#![cfg_attr(not(feature = \"std\"), no_std)]").unwrap();
-                       writeln!(out, "#[cfg(not(any(feature = \"std\", feature = \"no-std\")))]").unwrap();
-                       writeln!(out, "compile_error!(\"at least one of the `std` or `no-std` features must be enabled\");").unwrap();
+                       writeln!(out, "#![cfg_attr(feature = \"no-std\", no_std)]").unwrap();
                        writeln!(out, "extern crate alloc;").unwrap();
 
                        writeln!(out, "pub mod version;").unwrap();
                        writeln!(out, "extern crate alloc;").unwrap();
 
                        writeln!(out, "pub mod version;").unwrap();