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