]> git.bitcoin.ninja Git - ldk-c-bindings/commitdiff
Add helper method on results to return `result_ok`
authorMatt Corallo <git@bluematt.me>
Fri, 19 Nov 2021 20:11:56 +0000 (20:11 +0000)
committerMatt Corallo <git@bluematt.me>
Tue, 30 Nov 2021 15:39:48 +0000 (15:39 +0000)
This fixes https://github.com/lightningdevkit/ldk-garbagecollected/issues/59

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();