1// generated by diplomat-tool 2import { DataProvider } from "./DataProvider.mjs" 3import { DateTimeFormatterLoadError } from "./DateTimeFormatterLoadError.mjs" 4import { DateTimeLength } from "./DateTimeLength.mjs" 5import { Locale } from "./Locale.mjs" 6import { Time } from "./Time.mjs" 7import wasm from "./diplomat-wasm.mjs"; 8import * as diplomatRuntime from "./diplomat-runtime.mjs"; 9 10 11/** An ICU4X NoCalendarFormatter object capable of formatting an [`Time`] type (and others) as a string 12* 13*See the [Rust documentation for `NoCalendarFormatter`](https://docs.rs/icu/latest/icu/datetime/type.NoCalendarFormatter.html) for more information. 14* 15*Additional information: [1](https://docs.rs/icu/latest/icu/datetime/fieldsets/struct.T.html) 16*/ 17const NoCalendarFormatter_box_destroy_registry = new FinalizationRegistry((ptr) => { 18 wasm.icu4x_NoCalendarFormatter_destroy_mv1(ptr); 19}); 20 21export class NoCalendarFormatter { 22 23 // Internal ptr reference: 24 #ptr = null; 25 26 // Lifetimes are only to keep dependencies alive. 27 // Since JS won't garbage collect until there are no incoming edges. 28 #selfEdge = []; 29 30 #internalConstructor(symbol, ptr, selfEdge) { 31 if (symbol !== diplomatRuntime.internalConstructor) { 32 console.error("NoCalendarFormatter is an Opaque type. You cannot call its constructor."); 33 return; 34 } 35 36 this.#ptr = ptr; 37 this.#selfEdge = selfEdge; 38 39 // Are we being borrowed? If not, we can register. 40 if (this.#selfEdge.length === 0) { 41 NoCalendarFormatter_box_destroy_registry.register(this, this.#ptr); 42 } 43 44 return this; 45 } 46 get ffiValue() { 47 return this.#ptr; 48 } 49 50 static createWithLength(locale, length) { 51 const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); 52 53 const result = wasm.icu4x_NoCalendarFormatter_create_with_length_mv1(diplomatReceive.buffer, locale.ffiValue, length.ffiValue); 54 55 try { 56 if (!diplomatReceive.resultFlag) { 57 const cause = new DateTimeFormatterLoadError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); 58 throw new globalThis.Error('DateTimeFormatterLoadError: ' + cause.value, { cause }); 59 } 60 return new NoCalendarFormatter(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); 61 } 62 63 finally { 64 diplomatReceive.free(); 65 } 66 } 67 68 static createWithLengthAndProvider(provider, locale, length) { 69 const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); 70 71 const result = wasm.icu4x_NoCalendarFormatter_create_with_length_and_provider_mv1(diplomatReceive.buffer, provider.ffiValue, locale.ffiValue, length.ffiValue); 72 73 try { 74 if (!diplomatReceive.resultFlag) { 75 const cause = new DateTimeFormatterLoadError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); 76 throw new globalThis.Error('DateTimeFormatterLoadError: ' + cause.value, { cause }); 77 } 78 return new NoCalendarFormatter(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); 79 } 80 81 finally { 82 diplomatReceive.free(); 83 } 84 } 85 86 format(value) { 87 const write = new diplomatRuntime.DiplomatWriteBuf(wasm); 88 wasm.icu4x_NoCalendarFormatter_format_mv1(this.ffiValue, value.ffiValue, write.buffer); 89 90 try { 91 return write.readString8(); 92 } 93 94 finally { 95 write.free(); 96 } 97 } 98 99 constructor(symbol, ptr, selfEdge) { 100 return this.#internalConstructor(...arguments) 101 } 102}