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