// generated by diplomat-tool import { LeadingAdjustment } from "./LeadingAdjustment.mjs" import { TrailingCase } from "./TrailingCase.mjs" import wasm from "./diplomat-wasm.mjs"; import * as diplomatRuntime from "./diplomat-runtime.mjs"; /** See the [Rust documentation for `TitlecaseOptions`](https://docs.rs/icu/latest/icu/casemap/titlecase/struct.TitlecaseOptions.html) for more information. */ export class TitlecaseOptions { #leadingAdjustment; get leadingAdjustment() { return this.#leadingAdjustment; } set leadingAdjustment(value) { this.#leadingAdjustment = value; } #trailingCase; get trailingCase() { return this.#trailingCase; } set trailingCase(value) { this.#trailingCase = value; } constructor(structObj) { if (typeof structObj !== "object") { throw new Error("TitlecaseOptions's constructor takes an object of TitlecaseOptions's fields."); } if ("leadingAdjustment" in structObj) { this.#leadingAdjustment = structObj.leadingAdjustment; } else { this.#leadingAdjustment = null; } if ("trailingCase" in structObj) { this.#trailingCase = structObj.trailingCase; } else { this.#trailingCase = 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.#leadingAdjustment, 4, 4, false, (arrayBuffer, offset, jsValue) => [diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 0, jsValue.ffiValue, Int32Array)]), ...diplomatRuntime.optionToArgsForCalling(this.#trailingCase, 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.#leadingAdjustment, 4, 4, (arrayBuffer, offset, jsValue) => diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 0, jsValue.ffiValue, Int32Array)); diplomatRuntime.writeOptionToArrayBuffer(arrayBuffer, offset + 8, this.#trailingCase, 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("TitlecaseOptions._fromFFI is not meant to be called externally. Please use the default constructor."); } var structObj = {}; const leadingAdjustmentDeref = ptr; structObj.leadingAdjustment = diplomatRuntime.readOption(wasm, leadingAdjustmentDeref, 4, (wasm, offset) => { const deref = diplomatRuntime.enumDiscriminant(wasm, offset); return new LeadingAdjustment(diplomatRuntime.internalConstructor, deref) }); const trailingCaseDeref = ptr + 8; structObj.trailingCase = diplomatRuntime.readOption(wasm, trailingCaseDeref, 4, (wasm, offset) => { const deref = diplomatRuntime.enumDiscriminant(wasm, offset); return new TrailingCase(diplomatRuntime.internalConstructor, deref) }); return new TitlecaseOptions(structObj, internalConstructor); } static defaultOptions() { const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 16, 4, false); const result = wasm.icu4x_TitlecaseOptionsV1_default_mv1(diplomatReceive.buffer); try { return TitlecaseOptions._fromFFI(diplomatRuntime.internalConstructor, diplomatReceive.buffer); } finally { diplomatReceive.free(); } } }