Add helper method on results to return `result_ok`
[ldk-c-bindings] / c-bindings-gen / src / blocks.rs
index 57135789b71079f97961f1aa3e020acfcf64f4bf..6e6b897e9c13ce9cd9b21fdda30cbbbf28870a39 100644 (file)
@@ -124,6 +124,12 @@ pub fn write_result_block<W: std::io::Write>(w: &mut W, mangled_container: &str,
        writeln!(w, "\t}}").unwrap();
        writeln!(w, "}}").unwrap();
 
+       writeln!(w, "/// Checks if the given object is currently in the success state").unwrap();
+       writeln!(w, "#[no_mangle]").unwrap();
+       writeln!(w, "pub extern \"C\" fn {}_is_ok(o: &{}) -> bool {{", mangled_container, mangled_container).unwrap();
+       writeln!(w, "\to.result_ok").unwrap();
+       writeln!(w, "}}").unwrap();
+
        writeln!(w, "#[no_mangle]").unwrap();
        writeln!(w, "/// Frees any resources used by the {}.", mangled_container).unwrap();
        writeln!(w, "pub extern \"C\" fn {}_free(_res: {}) {{ }}", mangled_container, mangled_container).unwrap();