Update CI/Cargo.toml references to 0.0.122
[ldk-c-bindings] / c-bindings-gen / src / blocks.rs
index 5072f8ab06db481ae6e2954aa2dd4f3723d50b7f..664ca44b42414e142d4c5be4893646ebacdacddc 100644 (file)
@@ -250,7 +250,7 @@ pub fn write_vec_block<W: std::io::Write>(w: &mut W, mangled_container: &str, in
        writeln!(w, "impl Drop for {} {{", mangled_container).unwrap();
        writeln!(w, "\tfn drop(&mut self) {{").unwrap();
        writeln!(w, "\t\tif self.datalen == 0 {{ return; }}").unwrap();
-       writeln!(w, "\t\tunsafe {{ Box::from_raw(core::slice::from_raw_parts_mut(self.data, self.datalen)) }};").unwrap();
+       writeln!(w, "\t\tlet _ = unsafe {{ Box::from_raw(core::slice::from_raw_parts_mut(self.data, self.datalen)) }};").unwrap();
        writeln!(w, "\t}}").unwrap();
        writeln!(w, "}}").unwrap();
        if clonable {
@@ -442,7 +442,7 @@ fn writeln_docs_impl<'a, W: std::io::Write, I>(w: &mut W, attrs: &[syn::Attribut
                                match token_iter.next().unwrap() {
                                        TokenTree::Literal(lit) => {
                                                // Drop the first and last chars from lit as they are always "
-                                               let doc = format!("{}", lit);
+                                               let doc = format!("{}", lit).trim().replace("\n", &format!("\n{}//!", prefix));
                                                writeln!(w, "{}//!{}", prefix, &doc[1..doc.len() - 1]).unwrap();
                                        },
                                        _ => unimplemented!(),
@@ -452,7 +452,7 @@ fn writeln_docs_impl<'a, W: std::io::Write, I>(w: &mut W, attrs: &[syn::Attribut
                                match token_iter.next().unwrap() {
                                        TokenTree::Literal(lit) => {
                                                // Drop the first and last chars from lit as they are always "
-                                               let doc = format!("{}", lit);
+                                               let doc = format!("{}", lit).trim().replace("\n", &format!("\n{}///", prefix));
                                                writeln!(w, "{}///{}", prefix, &doc[1..doc.len() - 1]).unwrap();
                                        },
                                        _ => unimplemented!(),
@@ -576,7 +576,7 @@ pub fn write_method_params<W: std::io::Write>(w: &mut W, sig: &syn::Signature, t
                                        },
                                        _ => unimplemented!(),
                                }
-                               w.write(&c_type).unwrap();
+                               w.write_all(&c_type).unwrap();
                        }
                }
        }
@@ -747,7 +747,15 @@ pub fn write_method_call_params<W: std::io::Write>(w: &mut W, sig: &syn::Signatu
 
 /// Prints concrete generic parameters for a struct/trait/function, including the less-than and
 /// greater-than symbols, if any generic parameters are defined.
-pub fn maybe_write_generics<W: std::io::Write>(w: &mut W, generics: &syn::Generics, types: &TypeResolver, concrete_lifetimes: bool) {
+pub fn maybe_write_generics<W: std::io::Write>(w: &mut W, generics: &syn::Generics, generics_impld: &syn::PathArguments, types: &TypeResolver, concrete_lifetimes: bool) {
+       maybe_write_generics_intern(w, generics, generics_impld, types, concrete_lifetimes, false);
+}
+
+pub fn maybe_write_non_lifetime_generics<W: std::io::Write>(w: &mut W, generics: &syn::Generics, generics_impld: &syn::PathArguments, types: &TypeResolver) {
+       maybe_write_generics_intern(w, generics, generics_impld, types, false, true);
+}
+
+fn maybe_write_generics_intern<W: std::io::Write>(w: &mut W, generics: &syn::Generics, generics_impld: &syn::PathArguments, types: &TypeResolver, concrete_lifetimes: bool, dummy_lifetimes: bool) {
        let mut gen_types = GenericTypes::new(None);
        assert!(gen_types.learn_generics(generics, types));
        if generics.params.is_empty() { return; }
@@ -778,10 +786,20 @@ pub fn maybe_write_generics<W: std::io::Write>(w: &mut W, generics: &syn::Generi
                        syn::GenericParam::Type(type_param) => {
                                write!(w, "{}", if idx != 0 { ", " } else { "" }).unwrap();
                                let type_ident = &type_param.ident;
-                               types.write_c_type_in_generic_param(w, &syn::parse_quote!(#type_ident), Some(&gen_types), false);
+                               if types.understood_c_type(&syn::parse_quote!(#type_ident), Some(&gen_types)) {
+                                       types.write_c_type_in_generic_param(w, &syn::parse_quote!(#type_ident), Some(&gen_types), false);
+                               } else {
+                                       if let syn::PathArguments::AngleBracketed(args) = generics_impld {
+                                               if let syn::GenericArgument::Type(ty) = &args.args[idx] {
+                                                       types.write_c_type_in_generic_param(w, &ty, Some(&gen_types), false);
+                                               }
+                                       }
+                               }
                        },
                        syn::GenericParam::Lifetime(lt) => {
-                               if concrete_lifetimes {
+                               if dummy_lifetimes {
+                                       write!(w, "'_").unwrap();
+                               } else if concrete_lifetimes {
                                        write!(w, "'static").unwrap();
                                } else {
                                        write!(w, "{}'{}", if idx != 0 { ", " } else { "" }, lt.lifetime.ident).unwrap();