• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// generated by diplomat-tool
2import { DisplayNamesFallback } from "./DisplayNamesFallback.mjs"
3import { DisplayNamesStyle } from "./DisplayNamesStyle.mjs"
4import { LanguageDisplay } from "./LanguageDisplay.mjs"
5import wasm from "./diplomat-wasm.mjs";
6import * as diplomatRuntime from "./diplomat-runtime.mjs";
7
8
9/** See the [Rust documentation for `DisplayNamesOptions`](https://docs.rs/icu/latest/icu/displaynames/options/struct.DisplayNamesOptions.html) for more information.
10*/
11
12
13export class DisplayNamesOptions {
14
15    #style;
16
17    get style()  {
18        return this.#style;
19    }
20    set style(value) {
21        this.#style = value;
22    }
23
24    #fallback;
25
26    get fallback()  {
27        return this.#fallback;
28    }
29    set fallback(value) {
30        this.#fallback = value;
31    }
32
33    #languageDisplay;
34
35    get languageDisplay()  {
36        return this.#languageDisplay;
37    }
38    set languageDisplay(value) {
39        this.#languageDisplay = value;
40    }
41
42    /** Create `DisplayNamesOptions` from an object that contains all of `DisplayNamesOptions`s fields.
43    * Optional fields do not need to be included in the provided object.
44    */
45    static fromFields(structObj) {
46        return new DisplayNamesOptions(structObj);
47    }
48
49    #internalConstructor(structObj) {
50        if (typeof structObj !== "object") {
51            throw new Error("DisplayNamesOptions's constructor takes an object of DisplayNamesOptions's fields.");
52        }
53
54        if ("style" in structObj) {
55            this.#style = structObj.style;
56        } else {
57            this.#style = null;
58        }
59
60        if ("fallback" in structObj) {
61            this.#fallback = structObj.fallback;
62        } else {
63            this.#fallback = null;
64        }
65
66        if ("languageDisplay" in structObj) {
67            this.#languageDisplay = structObj.languageDisplay;
68        } else {
69            this.#languageDisplay = null;
70        }
71
72        return this;
73    }
74
75    // Return this struct in FFI function friendly format.
76    // Returns an array that can be expanded with spread syntax (...)
77
78    _intoFFI(
79        functionCleanupArena,
80        appendArrayMap
81    ) {
82        return [...diplomatRuntime.optionToArgsForCalling(this.#style, 4, 4, false, (arrayBuffer, offset, jsValue) => [diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 0, jsValue.ffiValue, Int32Array)]), ...diplomatRuntime.optionToArgsForCalling(this.#fallback, 4, 4, false, (arrayBuffer, offset, jsValue) => [diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 0, jsValue.ffiValue, Int32Array)]), ...diplomatRuntime.optionToArgsForCalling(this.#languageDisplay, 4, 4, false, (arrayBuffer, offset, jsValue) => [diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 0, jsValue.ffiValue, Int32Array)])]
83    }
84
85    static _fromSuppliedValue(internalConstructor, obj) {
86        if (internalConstructor !== diplomatRuntime.internalConstructor) {
87            throw new Error("_fromSuppliedValue cannot be called externally.");
88        }
89
90        if (obj instanceof DisplayNamesOptions) {
91            return obj;
92        }
93
94        return DisplayNamesOptions.fromFields(obj);
95    }
96
97    _writeToArrayBuffer(
98        arrayBuffer,
99        offset,
100        functionCleanupArena,
101        appendArrayMap
102    ) {
103        diplomatRuntime.writeOptionToArrayBuffer(arrayBuffer, offset + 0, this.#style, 4, 4, (arrayBuffer, offset, jsValue) => diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 0, jsValue.ffiValue, Int32Array));
104        diplomatRuntime.writeOptionToArrayBuffer(arrayBuffer, offset + 8, this.#fallback, 4, 4, (arrayBuffer, offset, jsValue) => diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 0, jsValue.ffiValue, Int32Array));
105        diplomatRuntime.writeOptionToArrayBuffer(arrayBuffer, offset + 16, this.#languageDisplay, 4, 4, (arrayBuffer, offset, jsValue) => diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 0, jsValue.ffiValue, Int32Array));
106    }
107
108    // This struct contains borrowed fields, so this takes in a list of
109    // "edges" corresponding to where each lifetime's data may have been borrowed from
110    // and passes it down to individual fields containing the borrow.
111    // This method does not attempt to handle any dependencies between lifetimes, the caller
112    // should handle this when constructing edge arrays.
113    static _fromFFI(internalConstructor, ptr) {
114        if (internalConstructor !== diplomatRuntime.internalConstructor) {
115            throw new Error("DisplayNamesOptions._fromFFI is not meant to be called externally. Please use the default constructor.");
116        }
117        let structObj = {};
118        const styleDeref = ptr;
119        structObj.style = diplomatRuntime.readOption(wasm, styleDeref, 4, (wasm, offset) => { const deref = diplomatRuntime.enumDiscriminant(wasm, offset); return new DisplayNamesStyle(diplomatRuntime.internalConstructor, deref) });
120        const fallbackDeref = ptr + 8;
121        structObj.fallback = diplomatRuntime.readOption(wasm, fallbackDeref, 4, (wasm, offset) => { const deref = diplomatRuntime.enumDiscriminant(wasm, offset); return new DisplayNamesFallback(diplomatRuntime.internalConstructor, deref) });
122        const languageDisplayDeref = ptr + 16;
123        structObj.languageDisplay = diplomatRuntime.readOption(wasm, languageDisplayDeref, 4, (wasm, offset) => { const deref = diplomatRuntime.enumDiscriminant(wasm, offset); return new LanguageDisplay(diplomatRuntime.internalConstructor, deref) });
124
125        return new DisplayNamesOptions(structObj);
126    }
127
128    constructor(structObj) {
129        return this.#internalConstructor(...arguments)
130    }
131}