• 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/** Increment used in a rounding operation.
7*
8*See the [Rust documentation for `RoundingIncrement`](https://docs.rs/fixed_decimal/latest/fixed_decimal/enum.RoundingIncrement.html) for more information.
9*/
10
11
12export class FixedDecimalRoundingIncrement {
13
14    #value = undefined;
15
16    static #values = new Map([
17        ["MultiplesOf1", 0],
18        ["MultiplesOf2", 1],
19        ["MultiplesOf5", 2],
20        ["MultiplesOf25", 3]
21    ]);
22
23    static getAllEntries() {
24        return FixedDecimalRoundingIncrement.#values.entries();
25    }
26
27    #internalConstructor(value) {
28        if (arguments.length > 1 && arguments[0] === diplomatRuntime.internalConstructor) {
29            // We pass in two internalConstructor arguments to create *new*
30            // instances of this type, otherwise the enums are treated as singletons.
31            if (arguments[1] === diplomatRuntime.internalConstructor ) {
32                this.#value = arguments[2];
33                return this;
34            }
35            return FixedDecimalRoundingIncrement.#objectValues[arguments[1]];
36        }
37
38        if (value instanceof FixedDecimalRoundingIncrement) {
39            return value;
40        }
41
42        let intVal = FixedDecimalRoundingIncrement.#values.get(value);
43
44        // Nullish check, checks for null or undefined
45        if (intVal != null) {
46            return FixedDecimalRoundingIncrement.#objectValues[intVal];
47        }
48
49        throw TypeError(value + " is not a FixedDecimalRoundingIncrement and does not correspond to any of its enumerator values.");
50    }
51
52    static fromValue(value) {
53        return new FixedDecimalRoundingIncrement(value);
54    }
55
56    get value() {
57        return [...FixedDecimalRoundingIncrement.#values.keys()][this.#value];
58    }
59
60    get ffiValue() {
61        return this.#value;
62    }
63    static #objectValues = [
64        new FixedDecimalRoundingIncrement(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 0),
65        new FixedDecimalRoundingIncrement(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 1),
66        new FixedDecimalRoundingIncrement(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2),
67        new FixedDecimalRoundingIncrement(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 3),
68    ];
69
70    static MultiplesOf1 = FixedDecimalRoundingIncrement.#objectValues[0];
71    static MultiplesOf2 = FixedDecimalRoundingIncrement.#objectValues[1];
72    static MultiplesOf5 = FixedDecimalRoundingIncrement.#objectValues[2];
73    static MultiplesOf25 = FixedDecimalRoundingIncrement.#objectValues[3];
74
75    constructor(value) {
76        return this.#internalConstructor(...arguments)
77    }
78}