Source code

Revision control

Copy as Markdown

Other Tools

// generated by diplomat-tool
import { DateMissingFieldsStrategy } from "./DateMissingFieldsStrategy.mjs"
import { DateOverflow } from "./DateOverflow.mjs"
import wasm from "./diplomat-wasm.mjs";
import * as diplomatRuntime from "./diplomat-runtime.mjs";
/**
* 🚧 This API is experimental and may experience breaking changes outside major releases.
*
* See the [Rust documentation for `DateFromFieldsOptions`](https://docs.rs/icu/2.1.1/icu/calendar/options/struct.DateFromFieldsOptions.html) for more information.
*/
export class DateFromFieldsOptions {
#overflow;
get overflow() {
return this.#overflow;
}
set overflow(value){
this.#overflow = value;
}
#missingFieldsStrategy;
get missingFieldsStrategy() {
return this.#missingFieldsStrategy;
}
set missingFieldsStrategy(value){
this.#missingFieldsStrategy = value;
}
/** @internal */
static fromFields(structObj) {
return new DateFromFieldsOptions(structObj);
}
#internalConstructor(structObj) {
if (typeof structObj !== "object") {
throw new Error("DateFromFieldsOptions's constructor takes an object of DateFromFieldsOptions's fields.");
}
if ("overflow" in structObj) {
this.#overflow = structObj.overflow;
} else {
this.#overflow = null;
}
if ("missingFieldsStrategy" in structObj) {
this.#missingFieldsStrategy = structObj.missingFieldsStrategy;
} else {
this.#missingFieldsStrategy = null;
}
return this;
}
// Return this struct in FFI function friendly format.
// Returns an array that can be expanded with spread syntax (...)
_intoFFI(
functionCleanupArena,
appendArrayMap
) {
let buffer = diplomatRuntime.DiplomatBuf.struct(wasm, 16, 4);
this._writeToArrayBuffer(wasm.memory.buffer, buffer.ptr, functionCleanupArena, appendArrayMap);
functionCleanupArena.alloc(buffer);
return buffer.ptr;
}
static _fromSuppliedValue(internalConstructor, obj) {
if (internalConstructor !== diplomatRuntime.internalConstructor) {
throw new Error("_fromSuppliedValue cannot be called externally.");
}
if (obj instanceof DateFromFieldsOptions) {
return obj;
}
return DateFromFieldsOptions.fromFields(obj);
}
_writeToArrayBuffer(
arrayBuffer,
offset,
functionCleanupArena,
appendArrayMap
) {
diplomatRuntime.writeOptionToArrayBuffer(arrayBuffer, offset + 0, this.#overflow, 4, 4, (arrayBuffer, offset, jsValue) => diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 0, jsValue.ffiValue, Int32Array));
diplomatRuntime.writeOptionToArrayBuffer(arrayBuffer, offset + 8, this.#missingFieldsStrategy, 4, 4, (arrayBuffer, offset, jsValue) => diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 0, jsValue.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("DateFromFieldsOptions._fromFFI is not meant to be called externally. Please use the default constructor.");
}
let structObj = {};
const overflowDeref = ptr;
structObj.overflow = diplomatRuntime.readOption(wasm, overflowDeref, 4, (wasm, offset) => { const deref = diplomatRuntime.enumDiscriminant(wasm, offset); return new DateOverflow(diplomatRuntime.internalConstructor, deref) });
const missingFieldsStrategyDeref = ptr + 8;
structObj.missingFieldsStrategy = diplomatRuntime.readOption(wasm, missingFieldsStrategyDeref, 4, (wasm, offset) => { const deref = diplomatRuntime.enumDiscriminant(wasm, offset); return new DateMissingFieldsStrategy(diplomatRuntime.internalConstructor, deref) });
return new DateFromFieldsOptions(structObj);
}
constructor(structObj) {
return this.#internalConstructor(...arguments)
}
}