blob: 273b977231de00c19d47d055da395f65f351da77 [file] [log] [blame]
// generated by diplomat-tool
import { UtcOffset } from "./UtcOffset.mjs"
import wasm from "./diplomat-wasm.mjs";
import * as diplomatRuntime from "./diplomat-runtime.mjs";
/** See the [Rust documentation for `UtcOffsets`](https://docs.rs/icu/latest/icu/time/zone/struct.UtcOffsets.html) for more information.
*/
export class UtcOffsets {
#standard;
get standard() {
return this.#standard;
}
#daylight;
get daylight() {
return this.#daylight;
}
#internalConstructor(structObj, internalConstructor) {
if (typeof structObj !== "object") {
throw new Error("UtcOffsets's constructor takes an object of UtcOffsets's fields.");
}
if (internalConstructor !== diplomatRuntime.internalConstructor) {
throw new Error("UtcOffsets is an out struct and can only be created internally.");
}
if ("standard" in structObj) {
this.#standard = structObj.standard;
} else {
throw new Error("Missing required field standard.");
}
if ("daylight" in structObj) {
this.#daylight = structObj.daylight;
} else {
throw new Error("Missing required field daylight.");
}
return this;
}
// Return this struct in FFI function friendly format.
// Returns an array that can be expanded with spread syntax (...)
_intoFFI(
functionCleanupArena,
appendArrayMap
) {
return [this.#standard.ffiValue, this.#daylight.ffiValue ?? 0]
}
static _fromSuppliedValue(internalConstructor, obj) {
if (internalConstructor !== diplomatRuntime.internalConstructor) {
throw new Error("_fromSuppliedValue cannot be called externally.");
}
if (obj instanceof UtcOffsets) {
return obj;
}
return UtcOffsets.fromFields(obj);
}
_writeToArrayBuffer(
arrayBuffer,
offset,
functionCleanupArena,
appendArrayMap
) {
diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 0, this.#standard.ffiValue, Uint32Array);
diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 4, this.#daylight.ffiValue ?? 0, Uint32Array);
}
// This struct contains borrowed fields, so this takes in a list of
// "edges" corresponding to where each lifetime's data may have been borrowed from
// and passes it down to individual fields containing the borrow.
// This method does not attempt to handle any dependencies between lifetimes, the caller
// should handle this when constructing edge arrays.
static _fromFFI(internalConstructor, ptr) {
if (internalConstructor !== diplomatRuntime.internalConstructor) {
throw new Error("UtcOffsets._fromFFI is not meant to be called externally. Please use the default constructor.");
}
let structObj = {};
const standardDeref = diplomatRuntime.ptrRead(wasm, ptr);
structObj.standard = new UtcOffset(diplomatRuntime.internalConstructor, standardDeref, []);
const daylightDeref = diplomatRuntime.ptrRead(wasm, ptr + 4);
structObj.daylight = daylightDeref === 0 ? null : new UtcOffset(diplomatRuntime.internalConstructor, daylightDeref, []);
return new UtcOffsets(structObj, internalConstructor);
}
constructor(structObj, internalConstructor) {
return this.#internalConstructor(...arguments)
}
}