From: Matt Corallo Date: Tue, 20 Oct 2020 18:02:12 +0000 (-0400) Subject: [bindings] Expose a _clone fn for every enum X-Git-Tag: v0.0.12~4^2~5 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=0362972d37e5078f6f160d3328778df90747fa93;p=rust-lightning [bindings] Expose a _clone fn for every enum This somewhat assumes that every public enum implements clone in some way, but that is currently the case. --- diff --git a/c-bindings-gen/src/main.rs b/c-bindings-gen/src/main.rs index b4a148fba..be3d36724 100644 --- a/c-bindings-gen/src/main.rs +++ b/c-bindings-gen/src/main.rs @@ -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); }