Source code

Revision control

Copy as Markdown

Other Tools

// generated by diplomat-tool
import { TimeZone } from "./TimeZone.mjs"
import wasm from "./diplomat-wasm.mjs";
import * as diplomatRuntime from "./diplomat-runtime.mjs";
/**
* See the [Rust documentation for `TimeZoneAndCanonical`](https://docs.rs/icu/latest/icu/time/zone/iana/struct.TimeZoneAndCanonical.html) for more information.
*/
export class TimeZoneAndCanonical {
#timeZone;
get timeZone() {
return this.#timeZone;
}
#canonical;
get canonical() {
return this.#canonical;
}
#internalConstructor(structObj, internalConstructor) {
if (typeof structObj !== "object") {
throw new Error("TimeZoneAndCanonical's constructor takes an object of TimeZoneAndCanonical's fields.");
}
if (internalConstructor !== diplomatRuntime.internalConstructor) {
throw new Error("TimeZoneAndCanonical is an out struct and can only be created internally.");
}
if ("timeZone" in structObj) {
this.#timeZone = structObj.timeZone;
} else {
throw new Error("Missing required field timeZone.");
}
if ("canonical" in structObj) {
this.#canonical = structObj.canonical;
} else {
throw new Error("Missing required field canonical.");
}
return this;
}
// Return this struct in FFI function friendly format.
// Returns an array that can be expanded with spread syntax (...)// If this struct contains any slices, their lifetime-edge-relevant information will be
// set up here, and can be appended to any relevant lifetime arrays here. <lifetime>AppendArray accepts a list
// 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
// output arrays. Null is equivalent to an empty list: this lifetime is not being borrowed from.
_intoFFI(
functionCleanupArena,
appendArrayMap
) {
return [this.#timeZone.ffiValue, ...diplomatRuntime.DiplomatBuf.str8(wasm, this.#canonical).splat()]
}
static _fromSuppliedValue(internalConstructor, obj) {
if (internalConstructor !== diplomatRuntime.internalConstructor) {
throw new Error("_fromSuppliedValue cannot be called externally.");
}
if (obj instanceof TimeZoneAndCanonical) {
return obj;
}
return TimeZoneAndCanonical.fromFields(obj);
}
_writeToArrayBuffer(
arrayBuffer,
offset,
functionCleanupArena,
appendArrayMap
) {
diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 0, this.#timeZone.ffiValue, Uint32Array);
diplomatRuntime.CleanupArena.maybeCreateWith(functionCleanupArena, ...appendArrayMap['aAppendArray']).alloc(diplomatRuntime.DiplomatBuf.str8(wasm, this.#canonical)).writePtrLenToArrayBuffer(arrayBuffer, offset + 4);
}
static _fromFFI(internalConstructor, ptr, aEdges) {
if (internalConstructor !== diplomatRuntime.internalConstructor) {
throw new Error("TimeZoneAndCanonical._fromFFI is not meant to be called externally. Please use the default constructor.");
}
let structObj = {};
const timeZoneDeref = diplomatRuntime.ptrRead(wasm, ptr);
structObj.timeZone = new TimeZone(diplomatRuntime.internalConstructor, timeZoneDeref, []);
const canonicalDeref = ptr + 4;
structObj.canonical = new diplomatRuntime.DiplomatSliceStr(wasm, canonicalDeref, "string8", aEdges).getValue();
return new TimeZoneAndCanonical(structObj, internalConstructor);
}
// Return all fields corresponding to lifetime `'a`
// without handling lifetime dependencies (this is the job of the caller)
// This is all fields that may be borrowed from if borrowing `'a`,
// assuming that there are no `'other: a`. bounds. In case of such bounds,
// the caller should take care to also call _fieldsForLifetimeOther
get _fieldsForLifetimeA() {
return [this.#canonical];
};
constructor(structObj, internalConstructor) {
return this.#internalConstructor(...arguments)
}
}