]> git.bitcoin.ninja Git - rust-lightning/commitdiff
[bindings] Expose a _clone fn for every enum
authorMatt Corallo <git@bluematt.me>
Tue, 20 Oct 2020 18:02:12 +0000 (14:02 -0400)
committerMatt Corallo <git@bluematt.me>
Mon, 23 Nov 2020 16:08:34 +0000 (11:08 -0500)
This somewhat assumes that every public enum implements clone in
some way, but that is currently the case.

c-bindings-gen/src/main.rs

index b4a148fbafcb967e34ffd426cf74cdbb9ddc6086..be3d36724853425184f0dc9fa78b5b91cde60850 100644 (file)
@@ -995,6 +995,10 @@ fn writeln_enum<'a, 'b, W: std::io::Write>(w: &mut W, e: &'a syn::ItemEnum, type
        if needs_free {
                writeln!(w, "#[no_mangle]\npub extern \"C\" fn {}_free(this_ptr: {}) {{ }}", e.ident, e.ident).unwrap();
        }
+       writeln!(w, "#[no_mangle]").unwrap();
+       writeln!(w, "pub extern \"C\" fn {}_clone(orig: &{}) -> {} {{", e.ident, e.ident, e.ident).unwrap();
+       writeln!(w, "\torig.clone()").unwrap();
+       writeln!(w, "}}").unwrap();
        write_cpp_wrapper(cpp_headers, &format!("{}", e.ident), needs_free);
 }