// generated by diplomat-tool import { CollatorAlternateHandling } from "./CollatorAlternateHandling.mjs" import { CollatorBackwardSecondLevel } from "./CollatorBackwardSecondLevel.mjs" import { CollatorCaseFirst } from "./CollatorCaseFirst.mjs" import { CollatorCaseLevel } from "./CollatorCaseLevel.mjs" import { CollatorMaxVariable } from "./CollatorMaxVariable.mjs" import { CollatorNumeric } from "./CollatorNumeric.mjs" import { CollatorStrength } from "./CollatorStrength.mjs" import wasm from "./diplomat-wasm.mjs"; import * as diplomatRuntime from "./diplomat-runtime.mjs"; /** See the [Rust documentation for `CollatorOptions`](https://docs.rs/icu/latest/icu/collator/struct.CollatorOptions.html) for more information. */ export class CollatorOptions { #strength; get strength() { return this.#strength; } set strength(value) { this.#strength = value; } #alternateHandling; get alternateHandling() { return this.#alternateHandling; } set alternateHandling(value) { this.#alternateHandling = value; } #caseFirst; get caseFirst() { return this.#caseFirst; } set caseFirst(value) { this.#caseFirst = value; } #maxVariable; get maxVariable() { return this.#maxVariable; } set maxVariable(value) { this.#maxVariable = value; } #caseLevel; get caseLevel() { return this.#caseLevel; } set caseLevel(value) { this.#caseLevel = value; } #numeric; get numeric() { return this.#numeric; } set numeric(value) { this.#numeric = value; } #backwardSecondLevel; get backwardSecondLevel() { return this.#backwardSecondLevel; } set backwardSecondLevel(value) { this.#backwardSecondLevel = value; } constructor(structObj) { if (typeof structObj !== "object") { throw new Error("CollatorOptions's constructor takes an object of CollatorOptions's fields."); } if ("strength" in structObj) { this.#strength = structObj.strength; } else { this.#strength = null; } if ("alternateHandling" in structObj) { this.#alternateHandling = structObj.alternateHandling; } else { this.#alternateHandling = null; } if ("caseFirst" in structObj) { this.#caseFirst = structObj.caseFirst; } else { this.#caseFirst = null; } if ("maxVariable" in structObj) { this.#maxVariable = structObj.maxVariable; } else { this.#maxVariable = null; } if ("caseLevel" in structObj) { this.#caseLevel = structObj.caseLevel; } else { this.#caseLevel = null; } if ("numeric" in structObj) { this.#numeric = structObj.numeric; } else { this.#numeric = null; } if ("backwardSecondLevel" in structObj) { this.#backwardSecondLevel = structObj.backwardSecondLevel; } else { this.#backwardSecondLevel = null; } } // Return this struct in FFI function friendly format. // Returns an array that can be expanded with spread syntax (...) _intoFFI( functionCleanupArena, appendArrayMap ) { 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.#caseFirst, 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.#numeric, 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)])] } _writeToArrayBuffer( arrayBuffer, offset, functionCleanupArena, appendArrayMap ) { diplomatRuntime.writeOptionToArrayBuffer(arrayBuffer, offset + 0, this.#strength, 4, 4, (arrayBuffer, offset, jsValue) => diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 0, jsValue.ffiValue, Int32Array)); diplomatRuntime.writeOptionToArrayBuffer(arrayBuffer, offset + 8, this.#alternateHandling, 4, 4, (arrayBuffer, offset, jsValue) => diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 0, jsValue.ffiValue, Int32Array)); diplomatRuntime.writeOptionToArrayBuffer(arrayBuffer, offset + 16, this.#caseFirst, 4, 4, (arrayBuffer, offset, jsValue) => diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 0, jsValue.ffiValue, Int32Array)); diplomatRuntime.writeOptionToArrayBuffer(arrayBuffer, offset + 24, this.#maxVariable, 4, 4, (arrayBuffer, offset, jsValue) => diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 0, jsValue.ffiValue, Int32Array)); diplomatRuntime.writeOptionToArrayBuffer(arrayBuffer, offset + 32, this.#caseLevel, 4, 4, (arrayBuffer, offset, jsValue) => diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 0, jsValue.ffiValue, Int32Array)); diplomatRuntime.writeOptionToArrayBuffer(arrayBuffer, offset + 40, this.#numeric, 4, 4, (arrayBuffer, offset, jsValue) => diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 0, jsValue.ffiValue, Int32Array)); diplomatRuntime.writeOptionToArrayBuffer(arrayBuffer, offset + 48, this.#backwardSecondLevel, 4, 4, (arrayBuffer, offset, jsValue) => diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 0, jsValue.ffiValue, Int32Array)); } // This struct contains borrowed fields, so this takes in a list of // "edges" corresponding to where each lifetime's data may have been borrowed from // and passes it down to individual fields containing the borrow. // This method does not attempt to handle any dependencies between lifetimes, the caller // should handle this when constructing edge arrays. static _fromFFI(internalConstructor, ptr) { if (internalConstructor !== diplomatRuntime.internalConstructor) { throw new Error("CollatorOptions._fromFFI is not meant to be called externally. Please use the default constructor."); } var structObj = {}; const strengthDeref = ptr; structObj.strength = diplomatRuntime.readOption(wasm, strengthDeref, 4, (wasm, offset) => { const deref = diplomatRuntime.enumDiscriminant(wasm, offset); return new CollatorStrength(diplomatRuntime.internalConstructor, deref) }); const alternateHandlingDeref = ptr + 8; structObj.alternateHandling = diplomatRuntime.readOption(wasm, alternateHandlingDeref, 4, (wasm, offset) => { const deref = diplomatRuntime.enumDiscriminant(wasm, offset); return new CollatorAlternateHandling(diplomatRuntime.internalConstructor, deref) }); const caseFirstDeref = ptr + 16; structObj.caseFirst = diplomatRuntime.readOption(wasm, caseFirstDeref, 4, (wasm, offset) => { const deref = diplomatRuntime.enumDiscriminant(wasm, offset); return new CollatorCaseFirst(diplomatRuntime.internalConstructor, deref) }); const maxVariableDeref = ptr + 24; structObj.maxVariable = diplomatRuntime.readOption(wasm, maxVariableDeref, 4, (wasm, offset) => { const deref = diplomatRuntime.enumDiscriminant(wasm, offset); return new CollatorMaxVariable(diplomatRuntime.internalConstructor, deref) }); const caseLevelDeref = ptr + 32; structObj.caseLevel = diplomatRuntime.readOption(wasm, caseLevelDeref, 4, (wasm, offset) => { const deref = diplomatRuntime.enumDiscriminant(wasm, offset); return new CollatorCaseLevel(diplomatRuntime.internalConstructor, deref) }); const numericDeref = ptr + 40; structObj.numeric = diplomatRuntime.readOption(wasm, numericDeref, 4, (wasm, offset) => { const deref = diplomatRuntime.enumDiscriminant(wasm, offset); return new CollatorNumeric(diplomatRuntime.internalConstructor, deref) }); const backwardSecondLevelDeref = ptr + 48; structObj.backwardSecondLevel = diplomatRuntime.readOption(wasm, backwardSecondLevelDeref, 4, (wasm, offset) => { const deref = diplomatRuntime.enumDiscriminant(wasm, offset); return new CollatorBackwardSecondLevel(diplomatRuntime.internalConstructor, deref) }); return new CollatorOptions(structObj, internalConstructor); } }