Add constructor utilities for generated Option<> types
[ldk-c-bindings] / c-bindings-gen / src / blocks.rs
index b6622617731fb14947cfe00e3f3f41582307a21b..4f957ce882ceb990c9e37411d1243ab522410f28 100644 (file)
@@ -315,6 +315,16 @@ pub fn write_option_block<W: std::io::Write>(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 {