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