b7c53e5f5237cb78520106633db306ea211513ad
[ldk-java] / src / main / java / org / ldk / structs / Result_ScorerDecodeErrorZ.java
1 package org.ldk.structs;
2
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
5 import org.ldk.util.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
9
10 public class Result_ScorerDecodeErrorZ extends CommonBase {
11         private Result_ScorerDecodeErrorZ(Object _dummy, long ptr) { super(ptr); }
12         protected void finalize() throws Throwable {
13                 if (ptr != 0) { bindings.CResult_ScorerDecodeErrorZ_free(ptr); } super.finalize();
14         }
15
16         static Result_ScorerDecodeErrorZ constr_from_ptr(long ptr) {
17                 if (bindings.CResult_ScorerDecodeErrorZ_is_ok(ptr)) {
18                         return new Result_ScorerDecodeErrorZ_OK(null, ptr);
19                 } else {
20                         return new Result_ScorerDecodeErrorZ_Err(null, ptr);
21                 }
22         }
23         public static final class Result_ScorerDecodeErrorZ_OK extends Result_ScorerDecodeErrorZ {
24                 public final Scorer res;
25                 private Result_ScorerDecodeErrorZ_OK(Object _dummy, long ptr) {
26                         super(_dummy, ptr);
27                         long res = bindings.CResult_ScorerDecodeErrorZ_get_ok(ptr);
28                         Scorer res_hu_conv = null; if (res < 0 || res > 4096) { res_hu_conv = new Scorer(null, res); }
29                         res_hu_conv.ptrs_to.add(this);
30                         this.res = res_hu_conv;
31                 }
32         }
33
34         public static final class Result_ScorerDecodeErrorZ_Err extends Result_ScorerDecodeErrorZ {
35                 public final DecodeError err;
36                 private Result_ScorerDecodeErrorZ_Err(Object _dummy, long ptr) {
37                         super(_dummy, ptr);
38                         long err = bindings.CResult_ScorerDecodeErrorZ_get_err(ptr);
39                         DecodeError err_hu_conv = null; if (err < 0 || err > 4096) { err_hu_conv = new DecodeError(null, err); }
40                         err_hu_conv.ptrs_to.add(this);
41                         this.err = err_hu_conv;
42                 }
43         }
44
45         /**
46          * Creates a new CResult_ScorerDecodeErrorZ in the success state.
47          */
48         public static Result_ScorerDecodeErrorZ ok(ScoringParameters o_params) {
49                 long ret = bindings.CResult_ScorerDecodeErrorZ_ok(bindings.Scorer_new(o_params == null ? 0 : o_params.ptr & ~1));
50                 Reference.reachabilityFence(o_params);
51                 if (ret >= 0 && ret <= 4096) { return null; }
52                 Result_ScorerDecodeErrorZ ret_hu_conv = Result_ScorerDecodeErrorZ.constr_from_ptr(ret);
53                 ret_hu_conv.ptrs_to.add(o_params);
54 // Due to rust's strict-ownership memory model, in some cases we need to "move"
55 // an object to pass exclusive ownership to the function being called.
56 // In most cases, we avoid ret_hu_conv being visible in GC'd languages by cloning the object
57 // at the FFI layer, creating a new object which Rust can claim ownership of
58 // However, in some cases (eg here), there is no way to clone an object, and thus
59 // we actually have to pass full ownership to Rust.
60 // Thus, after ret_hu_conv call, o_params is reset to null and is now a dummy object.
61 o_params.ptr = 0;;
62                 return ret_hu_conv;
63         }
64
65         /**
66          * Creates a new CResult_ScorerDecodeErrorZ in the error state.
67          */
68         public static Result_ScorerDecodeErrorZ err(DecodeError e) {
69                 long ret = bindings.CResult_ScorerDecodeErrorZ_err(e == null ? 0 : e.ptr & ~1);
70                 Reference.reachabilityFence(e);
71                 if (ret >= 0 && ret <= 4096) { return null; }
72                 Result_ScorerDecodeErrorZ ret_hu_conv = Result_ScorerDecodeErrorZ.constr_from_ptr(ret);
73                 return ret_hu_conv;
74         }
75
76         /**
77          * Checks if the given object is currently in the success state
78          */
79         public boolean is_ok() {
80                 boolean ret = bindings.CResult_ScorerDecodeErrorZ_is_ok(this.ptr);
81                 Reference.reachabilityFence(this);
82                 return ret;
83         }
84
85 }