From: Matt Corallo Date: Mon, 29 Mar 2021 19:23:21 +0000 (-0400) Subject: Add constructor utilities for generated Option<> types X-Git-Tag: v0.0.98~19^2~1 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=bdbc2f084dd2a2ffcec1e4f713bfea8ebbe3baa3;p=ldk-c-bindings Add constructor utilities for generated Option<> types --- diff --git a/c-bindings-gen/src/blocks.rs b/c-bindings-gen/src/blocks.rs index b662261..4f957ce 100644 --- a/c-bindings-gen/src/blocks.rs +++ b/c-bindings-gen/src/blocks.rs @@ -315,6 +315,16 @@ pub fn write_option_block(w: &mut W, mangled_container: &str, writeln!(w, "\t}}").unwrap(); writeln!(w, "}}").unwrap(); + writeln!(w, "#[no_mangle]").unwrap(); + writeln!(w, "pub extern \"C\" fn {}_some(o: {}) -> {} {{", mangled_container, inner_type, mangled_container).unwrap(); + writeln!(w, "\t{}::Some(o)", mangled_container).unwrap(); + writeln!(w, "}}").unwrap(); + + writeln!(w, "#[no_mangle]").unwrap(); + writeln!(w, "pub extern \"C\" fn {}_none() -> {} {{", mangled_container, mangled_container).unwrap(); + writeln!(w, "\t{}::None", mangled_container).unwrap(); + writeln!(w, "}}").unwrap(); + writeln!(w, "#[no_mangle]").unwrap(); writeln!(w, "pub extern \"C\" fn {}_free(_res: {}) {{ }}", mangled_container, mangled_container).unwrap(); if clonable {