1// generated by diplomat-tool 2import { TimeZone } from "./TimeZone.mjs" 3import wasm from "./diplomat-wasm.mjs"; 4import * as diplomatRuntime from "./diplomat-runtime.mjs"; 5 6 7 8export class TimeZoneAndCanonical { 9 10 #timeZone; 11 12 get timeZone() { 13 return this.#timeZone; 14 } 15 16 #canonical; 17 18 get canonical() { 19 return this.#canonical; 20 } 21 22 #internalConstructor(structObj, internalConstructor) { 23 if (typeof structObj !== "object") { 24 throw new Error("TimeZoneAndCanonical's constructor takes an object of TimeZoneAndCanonical's fields."); 25 } 26 27 if (internalConstructor !== diplomatRuntime.internalConstructor) { 28 throw new Error("TimeZoneAndCanonical is an out struct and can only be created internally."); 29 } 30 if ("timeZone" in structObj) { 31 this.#timeZone = structObj.timeZone; 32 } else { 33 throw new Error("Missing required field timeZone."); 34 } 35 36 if ("canonical" in structObj) { 37 this.#canonical = structObj.canonical; 38 } else { 39 throw new Error("Missing required field canonical."); 40 } 41 42 return this; 43 } 44 45 // Return this struct in FFI function friendly format. 46 // Returns an array that can be expanded with spread syntax (...) 47 // If this struct contains any slices, their lifetime-edge-relevant information will be 48 // set up here, and can be appended to any relevant lifetime arrays here. <lifetime>AppendArray accepts a list 49 // of arrays for each lifetime to do so. It accepts multiple lists per lifetime in case the caller needs to tie a lifetime to multiple 50 // output arrays. Null is equivalent to an empty list: this lifetime is not being borrowed from. 51 _intoFFI( 52 functionCleanupArena, 53 appendArrayMap 54 ) { 55 return [this.#timeZone.ffiValue, ...diplomatRuntime.CleanupArena.maybeCreateWith(functionCleanupArena, ...appendArrayMap['aAppendArray']).alloc(diplomatRuntime.DiplomatBuf.str8(wasm, this.#canonical)).splat()] 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 TimeZoneAndCanonical) { 64 return obj; 65 } 66 67 return TimeZoneAndCanonical.fromFields(obj); 68 } 69 70 _writeToArrayBuffer( 71 arrayBuffer, 72 offset, 73 functionCleanupArena, 74 appendArrayMap 75 ) { 76 diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 0, this.#timeZone.ffiValue, Uint32Array); 77 diplomatRuntime.CleanupArena.maybeCreateWith(functionCleanupArena, ...appendArrayMap['aAppendArray']).alloc(diplomatRuntime.DiplomatBuf.str8(wasm, this.#canonical)).writePtrLenToArrayBuffer(arrayBuffer, offset + 4); 78 } 79 80 static _fromFFI(internalConstructor, ptr, aEdges) { 81 if (internalConstructor !== diplomatRuntime.internalConstructor) { 82 throw new Error("TimeZoneAndCanonical._fromFFI is not meant to be called externally. Please use the default constructor."); 83 } 84 let structObj = {}; 85 const timeZoneDeref = diplomatRuntime.ptrRead(wasm, ptr); 86 structObj.timeZone = new TimeZone(diplomatRuntime.internalConstructor, timeZoneDeref, []); 87 const canonicalDeref = ptr + 4; 88 structObj.canonical = new diplomatRuntime.DiplomatSliceStr(wasm, canonicalDeref, "string8", aEdges).getValue(); 89 90 return new TimeZoneAndCanonical(structObj, internalConstructor); 91 } 92 93 // Return all fields corresponding to lifetime `'a` 94 // without handling lifetime dependencies (this is the job of the caller) 95 // This is all fields that may be borrowed from if borrowing `'a`, 96 // assuming that there are no `'other: a`. bounds. In case of such bounds, 97 // the caller should take care to also call _fieldsForLifetimeOther 98 get _fieldsForLifetimeA() { 99 return [canonical]; 100 }; 101 102 constructor(structObj, internalConstructor) { 103 return this.#internalConstructor(...arguments) 104 } 105}