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