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