Support printing lifetime generics on an impl-Trait block
[ldk-c-bindings] / c-bindings-gen / src / main.rs
index 46ae0e75fc5580262901f91af19f68b16dfe728d..d490a8901d363b53b7f83481de7c9844aeb6e20a 100644 (file)
@@ -559,7 +559,9 @@ fn writeln_trait<'a, 'b, W: std::io::Write>(w: &mut W, t: &'a syn::ItemTrait, ty
        // Finally, implement the original Rust trait for the newly created mapped trait.
        writeln!(w, "\nuse {}::{} as rust{};", types.module_path, t.ident, trait_name).unwrap();
        if implementable {
-               write!(w, "impl rust{}", t.ident).unwrap();
+               write!(w, "impl").unwrap();
+               maybe_write_lifetime_generics(w, &t.generics, types);
+               write!(w, " rust{}", t.ident).unwrap();
                maybe_write_generics(w, &t.generics, types, false);
                writeln!(w, " for {} {{", trait_name).unwrap();
                impl_trait_for_c!(t, "", types);
@@ -1853,7 +1855,8 @@ fn walk_ast<'a>(ast_storage: &'a FullLibraryAST, crate_types: &mut CrateTypes<'a
                                syn::Item::Impl(i) => {
                                        if let &syn::Type::Path(ref p) = &*i.self_ty {
                                                if let Some(trait_path) = i.trait_.as_ref() {
-                                                       if path_matches_nongeneric(&trait_path.1, &["core", "clone", "Clone"]) {
+                                                       if path_matches_nongeneric(&trait_path.1, &["core", "clone", "Clone"]) ||
+                                                          path_matches_nongeneric(&trait_path.1, &["Clone"]) {
                                                                if let Some(full_path) = import_resolver.maybe_resolve_path(&p.path, None) {
                                                                        crate_types.set_clonable("crate::".to_owned() + &full_path);
                                                                }
@@ -1904,6 +1907,9 @@ fn main() {
        writeln!(header_file, "#endif").unwrap();
        writeln!(cpp_header_file, "#include <string.h>\nnamespace LDK {{").unwrap();
 
+       // Write a few manually-defined types into the C++ header file
+       write_cpp_wrapper(&mut cpp_header_file, "Str", true, None);
+
        // First parse the full crate's ASTs, caching them so that we can hold references to the AST
        // objects in other datastructures:
        let mut lib_src = String::new();