1// generated by diplomat-tool 2import { Decimal } from "./Decimal.mjs" 3import { FixedDecimalParseError } from "./FixedDecimalParseError.mjs" 4import wasm from "./diplomat-wasm.mjs"; 5import * as diplomatRuntime from "./diplomat-runtime.mjs"; 6 7 8/** See the [Rust documentation for `PluralOperands`](https://docs.rs/icu/latest/icu/plurals/struct.PluralOperands.html) for more information. 9*/ 10const PluralOperands_box_destroy_registry = new FinalizationRegistry((ptr) => { 11 wasm.icu4x_PluralOperands_destroy_mv1(ptr); 12}); 13 14export class PluralOperands { 15 16 // Internal ptr reference: 17 #ptr = null; 18 19 // Lifetimes are only to keep dependencies alive. 20 // Since JS won't garbage collect until there are no incoming edges. 21 #selfEdge = []; 22 23 #internalConstructor(symbol, ptr, selfEdge) { 24 if (symbol !== diplomatRuntime.internalConstructor) { 25 console.error("PluralOperands is an Opaque type. You cannot call its constructor."); 26 return; 27 } 28 29 this.#ptr = ptr; 30 this.#selfEdge = selfEdge; 31 32 // Are we being borrowed? If not, we can register. 33 if (this.#selfEdge.length === 0) { 34 PluralOperands_box_destroy_registry.register(this, this.#ptr); 35 } 36 37 return this; 38 } 39 get ffiValue() { 40 return this.#ptr; 41 } 42 43 static fromString(s) { 44 let functionCleanupArena = new diplomatRuntime.CleanupArena(); 45 46 const sSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, s)); 47 48 const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); 49 50 const result = wasm.icu4x_PluralOperands_from_string_mv1(diplomatReceive.buffer, ...sSlice.splat()); 51 52 try { 53 if (!diplomatReceive.resultFlag) { 54 const cause = new FixedDecimalParseError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); 55 throw new globalThis.Error('FixedDecimalParseError: ' + cause.value, { cause }); 56 } 57 return new PluralOperands(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); 58 } 59 60 finally { 61 functionCleanupArena.free(); 62 63 diplomatReceive.free(); 64 } 65 } 66 67 static fromBigInt(i) { 68 const result = wasm.icu4x_PluralOperands_from_int64_mv1(i); 69 70 try { 71 return new PluralOperands(diplomatRuntime.internalConstructor, result, []); 72 } 73 74 finally {} 75 } 76 77 static fromFixedDecimal(x) { 78 const result = wasm.icu4x_PluralOperands_from_fixed_decimal_mv1(x.ffiValue); 79 80 try { 81 return new PluralOperands(diplomatRuntime.internalConstructor, result, []); 82 } 83 84 finally {} 85 } 86 87 constructor(symbol, ptr, selfEdge) { 88 return this.#internalConstructor(...arguments) 89 } 90}