1// generated by diplomat-tool 2import { LocaleFallbackPriority } from "./LocaleFallbackPriority.mjs" 3import wasm from "./diplomat-wasm.mjs"; 4import * as diplomatRuntime from "./diplomat-runtime.mjs"; 5 6 7/** Collection of configurations for the ICU4X fallback algorithm. 8* 9*See the [Rust documentation for `LocaleFallbackConfig`](https://docs.rs/icu/latest/icu/locale/fallback/struct.LocaleFallbackConfig.html) for more information. 10*/ 11 12 13export class LocaleFallbackConfig { 14 15 #priority; 16 17 get priority() { 18 return this.#priority; 19 } 20 set priority(value) { 21 this.#priority = value; 22 } 23 24 /** Create `LocaleFallbackConfig` from an object that contains all of `LocaleFallbackConfig`s fields. 25 * Optional fields do not need to be included in the provided object. 26 */ 27 static fromFields(structObj) { 28 return new LocaleFallbackConfig(structObj); 29 } 30 31 #internalConstructor(structObj) { 32 if (typeof structObj !== "object") { 33 throw new Error("LocaleFallbackConfig's constructor takes an object of LocaleFallbackConfig's fields."); 34 } 35 36 if ("priority" in structObj) { 37 this.#priority = structObj.priority; 38 } else { 39 throw new Error("Missing required field priority."); 40 } 41 42 return this; 43 } 44 45 // Return this struct in FFI function friendly format. 46 // Returns an array that can be expanded with spread syntax (...) 47 48 _intoFFI( 49 functionCleanupArena, 50 appendArrayMap 51 ) { 52 return [this.#priority.ffiValue] 53 } 54 55 static _fromSuppliedValue(internalConstructor, obj) { 56 if (internalConstructor !== diplomatRuntime.internalConstructor) { 57 throw new Error("_fromSuppliedValue cannot be called externally."); 58 } 59 60 if (obj instanceof LocaleFallbackConfig) { 61 return obj; 62 } 63 64 return LocaleFallbackConfig.fromFields(obj); 65 } 66 67 _writeToArrayBuffer( 68 arrayBuffer, 69 offset, 70 functionCleanupArena, 71 appendArrayMap 72 ) { 73 diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 0, this.#priority.ffiValue, Int32Array); 74 } 75 76 // This struct contains borrowed fields, so this takes in a list of 77 // "edges" corresponding to where each lifetime's data may have been borrowed from 78 // and passes it down to individual fields containing the borrow. 79 // This method does not attempt to handle any dependencies between lifetimes, the caller 80 // should handle this when constructing edge arrays. 81 static _fromFFI(internalConstructor, ptr) { 82 if (internalConstructor !== diplomatRuntime.internalConstructor) { 83 throw new Error("LocaleFallbackConfig._fromFFI is not meant to be called externally. Please use the default constructor."); 84 } 85 let structObj = {}; 86 const priorityDeref = diplomatRuntime.enumDiscriminant(wasm, ptr); 87 structObj.priority = new LocaleFallbackPriority(diplomatRuntime.internalConstructor, priorityDeref); 88 89 return new LocaleFallbackConfig(structObj); 90 } 91 92 constructor(structObj) { 93 return this.#internalConstructor(...arguments) 94 } 95}