• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// generated by diplomat-tool
2import wasm from "./diplomat-wasm.mjs";
3import * as diplomatRuntime from "./diplomat-runtime.mjs";
4
5
6/** Mode used in a rounding operation for signed numbers.
7*
8*See the [Rust documentation for `SignedRoundingMode`](https://docs.rs/fixed_decimal/latest/fixed_decimal/enum.SignedRoundingMode.html) for more information.
9*/
10
11
12export class FixedDecimalSignedRoundingMode {
13
14    #value = undefined;
15
16    static #values = new Map([
17        ["Expand", 0],
18        ["Trunc", 1],
19        ["HalfExpand", 2],
20        ["HalfTrunc", 3],
21        ["HalfEven", 4],
22        ["Ceil", 5],
23        ["Floor", 6],
24        ["HalfCeil", 7],
25        ["HalfFloor", 8]
26    ]);
27
28    static getAllEntries() {
29        return FixedDecimalSignedRoundingMode.#values.entries();
30    }
31
32    #internalConstructor(value) {
33        if (arguments.length > 1 && arguments[0] === diplomatRuntime.internalConstructor) {
34            // We pass in two internalConstructor arguments to create *new*
35            // instances of this type, otherwise the enums are treated as singletons.
36            if (arguments[1] === diplomatRuntime.internalConstructor ) {
37                this.#value = arguments[2];
38                return this;
39            }
40            return FixedDecimalSignedRoundingMode.#objectValues[arguments[1]];
41        }
42
43        if (value instanceof FixedDecimalSignedRoundingMode) {
44            return value;
45        }
46
47        let intVal = FixedDecimalSignedRoundingMode.#values.get(value);
48
49        // Nullish check, checks for null or undefined
50        if (intVal != null) {
51            return FixedDecimalSignedRoundingMode.#objectValues[intVal];
52        }
53
54        throw TypeError(value + " is not a FixedDecimalSignedRoundingMode and does not correspond to any of its enumerator values.");
55    }
56
57    static fromValue(value) {
58        return new FixedDecimalSignedRoundingMode(value);
59    }
60
61    get value() {
62        return [...FixedDecimalSignedRoundingMode.#values.keys()][this.#value];
63    }
64
65    get ffiValue() {
66        return this.#value;
67    }
68    static #objectValues = [
69        new FixedDecimalSignedRoundingMode(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 0),
70        new FixedDecimalSignedRoundingMode(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 1),
71        new FixedDecimalSignedRoundingMode(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2),
72        new FixedDecimalSignedRoundingMode(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 3),
73        new FixedDecimalSignedRoundingMode(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 4),
74        new FixedDecimalSignedRoundingMode(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 5),
75        new FixedDecimalSignedRoundingMode(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 6),
76        new FixedDecimalSignedRoundingMode(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 7),
77        new FixedDecimalSignedRoundingMode(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 8),
78    ];
79
80    static Expand = FixedDecimalSignedRoundingMode.#objectValues[0];
81    static Trunc = FixedDecimalSignedRoundingMode.#objectValues[1];
82    static HalfExpand = FixedDecimalSignedRoundingMode.#objectValues[2];
83    static HalfTrunc = FixedDecimalSignedRoundingMode.#objectValues[3];
84    static HalfEven = FixedDecimalSignedRoundingMode.#objectValues[4];
85    static Ceil = FixedDecimalSignedRoundingMode.#objectValues[5];
86    static Floor = FixedDecimalSignedRoundingMode.#objectValues[6];
87    static HalfCeil = FixedDecimalSignedRoundingMode.#objectValues[7];
88    static HalfFloor = FixedDecimalSignedRoundingMode.#objectValues[8];
89
90    constructor(value) {
91        return this.#internalConstructor(...arguments)
92    }
93}