Bindings updates
[ldk-java] / ts / structs / Result_NetworkGraphDecodeErrorZ.ts
index c66bd013f8e7abf4013aaff59cf5bec9ad670f5a..38c3c2989d9cf7535a1612cd7e1dd2c4bfba3849 100644 (file)
@@ -19,13 +19,22 @@ public class Result_NetworkGraphDecodeErrorZ extends CommonBase {
                public final NetworkGraph res;
                private Result_NetworkGraphDecodeErrorZ_OK(Object _dummy, long ptr) {
                        super(_dummy, ptr);
-                       uint32_t res = bindings.LDKCResult_NetworkGraphDecodeErrorZ_get_ok(ptr);
-                       NetworkGraph res_hu_conv = new NetworkGraph(null, res);
+                       number res = bindings.LDKCResult_NetworkGraphDecodeErrorZ_get_ok(ptr);
+                       const res_hu_conv: NetworkGraph = new NetworkGraph(null, res);
+                       res_hu_conv.ptrs_to.add(this);
                        this.res = res_hu_conv;
                }
                public Result_NetworkGraphDecodeErrorZ_OK(NetworkGraph res) {
                        this(null, bindings.CResult_NetworkGraphDecodeErrorZ_ok(res == null ? 0 : res.ptr & ~1));
                        this.ptrs_to.add(res);
+                       // Due to rust's strict-ownership memory model, in some cases we need to "move"
+                       // an object to pass exclusive ownership to the function being called.
+                       // In most cases, we avoid this being visible in GC'd languages by cloning the object
+                       // at the FFI layer, creating a new object which Rust can claim ownership of
+                       // However, in some cases (eg here), there is no way to clone an object, and thus
+                       // we actually have to pass full ownership to Rust.
+                       // Thus, after this call, res is reset to null and is now a dummy object.
+                       res.ptr = 0;
                }
        }
 
@@ -33,8 +42,9 @@ public class Result_NetworkGraphDecodeErrorZ extends CommonBase {
                public final DecodeError err;
                private Result_NetworkGraphDecodeErrorZ_Err(Object _dummy, long ptr) {
                        super(_dummy, ptr);
-                       uint32_t err = bindings.LDKCResult_NetworkGraphDecodeErrorZ_get_err(ptr);
-                       DecodeError err_hu_conv = new DecodeError(null, err);
+                       number err = bindings.LDKCResult_NetworkGraphDecodeErrorZ_get_err(ptr);
+                       const err_hu_conv: DecodeError = new DecodeError(null, err);
+                       err_hu_conv.ptrs_to.add(this);
                        this.err = err_hu_conv;
                }
                public Result_NetworkGraphDecodeErrorZ_Err(DecodeError err) {