• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// generated by diplomat-tool
2import { CollatorAlternateHandling } from "./CollatorAlternateHandling.mjs"
3import { CollatorBackwardSecondLevel } from "./CollatorBackwardSecondLevel.mjs"
4import { CollatorCaseFirst } from "./CollatorCaseFirst.mjs"
5import { CollatorCaseLevel } from "./CollatorCaseLevel.mjs"
6import { CollatorMaxVariable } from "./CollatorMaxVariable.mjs"
7import { CollatorNumericOrdering } from "./CollatorNumericOrdering.mjs"
8import { CollatorStrength } from "./CollatorStrength.mjs"
9import wasm from "./diplomat-wasm.mjs";
10import * as diplomatRuntime from "./diplomat-runtime.mjs";
11
12
13/** See the [Rust documentation for `ResolvedCollatorOptions`](https://docs.rs/icu/latest/icu/collator/options/struct.ResolvedCollatorOptions.html) for more information.
14*/
15
16
17export class CollatorResolvedOptions {
18
19    #strength;
20
21    get strength()  {
22        return this.#strength;
23    }
24
25    #alternateHandling;
26
27    get alternateHandling()  {
28        return this.#alternateHandling;
29    }
30
31    #caseFirst;
32
33    get caseFirst()  {
34        return this.#caseFirst;
35    }
36
37    #maxVariable;
38
39    get maxVariable()  {
40        return this.#maxVariable;
41    }
42
43    #caseLevel;
44
45    get caseLevel()  {
46        return this.#caseLevel;
47    }
48
49    #numeric;
50
51    get numeric()  {
52        return this.#numeric;
53    }
54
55    #backwardSecondLevel;
56
57    get backwardSecondLevel()  {
58        return this.#backwardSecondLevel;
59    }
60
61    #internalConstructor(structObj, internalConstructor) {
62        if (typeof structObj !== "object") {
63            throw new Error("CollatorResolvedOptions's constructor takes an object of CollatorResolvedOptions's fields.");
64        }
65
66        if (internalConstructor !== diplomatRuntime.internalConstructor) {
67            throw new Error("CollatorResolvedOptions is an out struct and can only be created internally.");
68        }
69        if ("strength" in structObj) {
70            this.#strength = structObj.strength;
71        } else {
72            throw new Error("Missing required field strength.");
73        }
74
75        if ("alternateHandling" in structObj) {
76            this.#alternateHandling = structObj.alternateHandling;
77        } else {
78            throw new Error("Missing required field alternateHandling.");
79        }
80
81        if ("caseFirst" in structObj) {
82            this.#caseFirst = structObj.caseFirst;
83        } else {
84            throw new Error("Missing required field caseFirst.");
85        }
86
87        if ("maxVariable" in structObj) {
88            this.#maxVariable = structObj.maxVariable;
89        } else {
90            throw new Error("Missing required field maxVariable.");
91        }
92
93        if ("caseLevel" in structObj) {
94            this.#caseLevel = structObj.caseLevel;
95        } else {
96            throw new Error("Missing required field caseLevel.");
97        }
98
99        if ("numeric" in structObj) {
100            this.#numeric = structObj.numeric;
101        } else {
102            throw new Error("Missing required field numeric.");
103        }
104
105        if ("backwardSecondLevel" in structObj) {
106            this.#backwardSecondLevel = structObj.backwardSecondLevel;
107        } else {
108            throw new Error("Missing required field backwardSecondLevel.");
109        }
110
111        return this;
112    }
113
114    // Return this struct in FFI function friendly format.
115    // Returns an array that can be expanded with spread syntax (...)
116
117    _intoFFI(
118        functionCleanupArena,
119        appendArrayMap
120    ) {
121        return [this.#strength.ffiValue, this.#alternateHandling.ffiValue, this.#caseFirst.ffiValue, this.#maxVariable.ffiValue, this.#caseLevel.ffiValue, this.#numeric.ffiValue, this.#backwardSecondLevel.ffiValue]
122    }
123
124    static _fromSuppliedValue(internalConstructor, obj) {
125        if (internalConstructor !== diplomatRuntime.internalConstructor) {
126            throw new Error("_fromSuppliedValue cannot be called externally.");
127        }
128
129        if (obj instanceof CollatorResolvedOptions) {
130            return obj;
131        }
132
133        return CollatorResolvedOptions.fromFields(obj);
134    }
135
136    _writeToArrayBuffer(
137        arrayBuffer,
138        offset,
139        functionCleanupArena,
140        appendArrayMap
141    ) {
142        diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 0, this.#strength.ffiValue, Int32Array);
143        diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 4, this.#alternateHandling.ffiValue, Int32Array);
144        diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 8, this.#caseFirst.ffiValue, Int32Array);
145        diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 12, this.#maxVariable.ffiValue, Int32Array);
146        diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 16, this.#caseLevel.ffiValue, Int32Array);
147        diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 20, this.#numeric.ffiValue, Int32Array);
148        diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 24, this.#backwardSecondLevel.ffiValue, Int32Array);
149    }
150
151    // This struct contains borrowed fields, so this takes in a list of
152    // "edges" corresponding to where each lifetime's data may have been borrowed from
153    // and passes it down to individual fields containing the borrow.
154    // This method does not attempt to handle any dependencies between lifetimes, the caller
155    // should handle this when constructing edge arrays.
156    static _fromFFI(internalConstructor, ptr) {
157        if (internalConstructor !== diplomatRuntime.internalConstructor) {
158            throw new Error("CollatorResolvedOptions._fromFFI is not meant to be called externally. Please use the default constructor.");
159        }
160        let structObj = {};
161        const strengthDeref = diplomatRuntime.enumDiscriminant(wasm, ptr);
162        structObj.strength = new CollatorStrength(diplomatRuntime.internalConstructor, strengthDeref);
163        const alternateHandlingDeref = diplomatRuntime.enumDiscriminant(wasm, ptr + 4);
164        structObj.alternateHandling = new CollatorAlternateHandling(diplomatRuntime.internalConstructor, alternateHandlingDeref);
165        const caseFirstDeref = diplomatRuntime.enumDiscriminant(wasm, ptr + 8);
166        structObj.caseFirst = new CollatorCaseFirst(diplomatRuntime.internalConstructor, caseFirstDeref);
167        const maxVariableDeref = diplomatRuntime.enumDiscriminant(wasm, ptr + 12);
168        structObj.maxVariable = new CollatorMaxVariable(diplomatRuntime.internalConstructor, maxVariableDeref);
169        const caseLevelDeref = diplomatRuntime.enumDiscriminant(wasm, ptr + 16);
170        structObj.caseLevel = new CollatorCaseLevel(diplomatRuntime.internalConstructor, caseLevelDeref);
171        const numericDeref = diplomatRuntime.enumDiscriminant(wasm, ptr + 20);
172        structObj.numeric = new CollatorNumericOrdering(diplomatRuntime.internalConstructor, numericDeref);
173        const backwardSecondLevelDeref = diplomatRuntime.enumDiscriminant(wasm, ptr + 24);
174        structObj.backwardSecondLevel = new CollatorBackwardSecondLevel(diplomatRuntime.internalConstructor, backwardSecondLevelDeref);
175
176        return new CollatorResolvedOptions(structObj, internalConstructor);
177    }
178
179    constructor(structObj, internalConstructor) {
180        return this.#internalConstructor(...arguments)
181    }
182}