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