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