| // generated by diplomat-tool |
| import { WeekRelativeUnit } from "./WeekRelativeUnit.mjs" |
| import wasm from "./diplomat-wasm.mjs"; |
| import * as diplomatRuntime from "./diplomat-runtime.mjs"; |
| |
| |
| /** See the [Rust documentation for `WeekOf`](https://docs.rs/icu/latest/icu/calendar/week/struct.WeekOf.html) for more information. |
| */ |
| |
| |
| export class WeekOf { |
| |
| #week; |
| |
| get week() { |
| return this.#week; |
| } |
| |
| #unit; |
| |
| get unit() { |
| return this.#unit; |
| } |
| |
| #internalConstructor(structObj, internalConstructor) { |
| if (typeof structObj !== "object") { |
| throw new Error("WeekOf's constructor takes an object of WeekOf's fields."); |
| } |
| |
| if (internalConstructor !== diplomatRuntime.internalConstructor) { |
| throw new Error("WeekOf is an out struct and can only be created internally."); |
| } |
| if ("week" in structObj) { |
| this.#week = structObj.week; |
| } else { |
| throw new Error("Missing required field week."); |
| } |
| |
| if ("unit" in structObj) { |
| this.#unit = structObj.unit; |
| } else { |
| throw new Error("Missing required field unit."); |
| } |
| |
| return this; |
| } |
| |
| // Return this struct in FFI function friendly format. |
| // Returns an array that can be expanded with spread syntax (...) |
| |
| // JS structs need to be generated with or without padding depending on whether they are being passed as aggregates or splatted out into fields. |
| // Most of the time this is known beforehand: large structs (>2 scalar fields) always get padding, and structs passed directly in parameters omit padding |
| // if they are small. However small structs within large structs also get padding, and we signal that by setting forcePadding. |
| _intoFFI( |
| functionCleanupArena, |
| appendArrayMap, |
| forcePadding |
| ) { |
| return [this.#week, ...diplomatRuntime.maybePaddingFields(forcePadding, 3 /* x i8 */), this.#unit.ffiValue] |
| } |
| |
| static _fromSuppliedValue(internalConstructor, obj) { |
| if (internalConstructor !== diplomatRuntime.internalConstructor) { |
| throw new Error("_fromSuppliedValue cannot be called externally."); |
| } |
| |
| if (obj instanceof WeekOf) { |
| return obj; |
| } |
| |
| return WeekOf.fromFields(obj); |
| } |
| |
| _writeToArrayBuffer( |
| arrayBuffer, |
| offset, |
| functionCleanupArena, |
| appendArrayMap, |
| forcePadding |
| ) { |
| diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 0, this.#week, Uint8Array); |
| diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 4, this.#unit.ffiValue, Int32Array); |
| } |
| |
| // 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("WeekOf._fromFFI is not meant to be called externally. Please use the default constructor."); |
| } |
| let structObj = {}; |
| const weekDeref = (new Uint8Array(wasm.memory.buffer, ptr, 1))[0]; |
| structObj.week = weekDeref; |
| const unitDeref = diplomatRuntime.enumDiscriminant(wasm, ptr + 4); |
| structObj.unit = new WeekRelativeUnit(diplomatRuntime.internalConstructor, unitDeref); |
| |
| return new WeekOf(structObj, internalConstructor); |
| } |
| |
| constructor(structObj, internalConstructor) { |
| return this.#internalConstructor(...arguments) |
| } |
| } |