diff --git a/Cargo.lock b/Cargo.lock index 98b59e6f7f1..a79ab6cad7d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -600,7 +600,7 @@ dependencies = [ [[package]] name = "diplomat" version = "0.8.0" -source = "git+https://github.com/rust-diplomat/diplomat?rev=772da44c9ee66862eaafb23a40a197d7da499007#772da44c9ee66862eaafb23a40a197d7da499007" +source = "git+https://github.com/rust-diplomat/diplomat?rev=3b875c676f60a892eeb818c6a0f6f10086c69a24#3b875c676f60a892eeb818c6a0f6f10086c69a24" dependencies = [ "diplomat_core", "proc-macro2", @@ -618,7 +618,7 @@ dependencies = [ [[package]] name = "diplomat-runtime" version = "0.8.1" -source = "git+https://github.com/rust-diplomat/diplomat?rev=772da44c9ee66862eaafb23a40a197d7da499007#772da44c9ee66862eaafb23a40a197d7da499007" +source = "git+https://github.com/rust-diplomat/diplomat?rev=3b875c676f60a892eeb818c6a0f6f10086c69a24#3b875c676f60a892eeb818c6a0f6f10086c69a24" dependencies = [ "log", ] @@ -626,7 +626,7 @@ dependencies = [ [[package]] name = "diplomat-tool" version = "0.8.0" -source = "git+https://github.com/rust-diplomat/diplomat?rev=772da44c9ee66862eaafb23a40a197d7da499007#772da44c9ee66862eaafb23a40a197d7da499007" +source = "git+https://github.com/rust-diplomat/diplomat?rev=3b875c676f60a892eeb818c6a0f6f10086c69a24#3b875c676f60a892eeb818c6a0f6f10086c69a24" dependencies = [ "askama", "clap", @@ -646,7 +646,7 @@ dependencies = [ [[package]] name = "diplomat_core" version = "0.8.0" -source = "git+https://github.com/rust-diplomat/diplomat?rev=772da44c9ee66862eaafb23a40a197d7da499007#772da44c9ee66862eaafb23a40a197d7da499007" +source = "git+https://github.com/rust-diplomat/diplomat?rev=3b875c676f60a892eeb818c6a0f6f10086c69a24#3b875c676f60a892eeb818c6a0f6f10086c69a24" dependencies = [ "displaydoc", "either", diff --git a/Cargo.toml b/Cargo.toml index a8e14df7e3f..0f84928201a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -208,10 +208,10 @@ icu_benchmark_macros = { path = "tools/benchmark/macros" } # The version here can either be a `version = ".."` spec or `git = "https://github.com/rust-diplomat/diplomat", rev = ".."` # Diplomat must be published preceding a new ICU4X release but may use git versions in between -diplomat = { git = "https://github.com/rust-diplomat/diplomat", rev = "772da44c9ee66862eaafb23a40a197d7da499007" } -diplomat-runtime = { git = "https://github.com/rust-diplomat/diplomat", rev = "772da44c9ee66862eaafb23a40a197d7da499007" } -diplomat_core = { git = "https://github.com/rust-diplomat/diplomat", rev = "772da44c9ee66862eaafb23a40a197d7da499007" } -diplomat-tool = { git = "https://github.com/rust-diplomat/diplomat", rev = "772da44c9ee66862eaafb23a40a197d7da499007" } +diplomat = { git = "https://github.com/rust-diplomat/diplomat", rev = "3b875c676f60a892eeb818c6a0f6f10086c69a24" } +diplomat-runtime = { git = "https://github.com/rust-diplomat/diplomat", rev = "3b875c676f60a892eeb818c6a0f6f10086c69a24" } +diplomat_core = { git = "https://github.com/rust-diplomat/diplomat", rev = "3b875c676f60a892eeb818c6a0f6f10086c69a24" } +diplomat-tool = { git = "https://github.com/rust-diplomat/diplomat", rev = "3b875c676f60a892eeb818c6a0f6f10086c69a24" } # EXTERNAL DEPENDENCIES # diff --git a/ffi/capi/bindings/c/Collator.h b/ffi/capi/bindings/c/Collator.h index e8c308d24c3..8088e2b7260 100644 --- a/ffi/capi/bindings/c/Collator.h +++ b/ffi/capi/bindings/c/Collator.h @@ -23,9 +23,9 @@ typedef struct ICU4XCollator_create_v1_result {union {Collator* ok; DataError err;}; bool is_ok;} ICU4XCollator_create_v1_result; ICU4XCollator_create_v1_result ICU4XCollator_create_v1(const DataProvider* provider, const Locale* locale, CollatorOptionsV1 options); -int8_t ICU4XCollator_compare_utf16_(const Collator* self, const char16_t* left_data, size_t left_len, const char16_t* right_data, size_t right_len); +int8_t ICU4XCollator_compare_utf16(const Collator* self, const char16_t* left_data, size_t left_len, const char16_t* right_data, size_t right_len); -int8_t ICU4XCollator_compare_(const Collator* self, const char* left_data, size_t left_len, const char* right_data, size_t right_len); +int8_t ICU4XCollator_compare(const Collator* self, const char* left_data, size_t left_len, const char* right_data, size_t right_len); CollatorResolvedOptionsV1 ICU4XCollator_resolved_options(const Collator* self); diff --git a/ffi/capi/bindings/c/Locale.h b/ffi/capi/bindings/c/Locale.h index dfcdbc945a6..a524e9a86e7 100644 --- a/ffi/capi/bindings/c/Locale.h +++ b/ffi/capi/bindings/c/Locale.h @@ -52,9 +52,9 @@ void ICU4XLocale_to_string(const Locale* self, DiplomatWrite* write); bool ICU4XLocale_normalizing_eq(const Locale* self, const char* other_data, size_t other_len); -int8_t ICU4XLocale_strict_cmp_(const Locale* self, const char* other_data, size_t other_len); +int8_t ICU4XLocale_compare_to_string(const Locale* self, const char* other_data, size_t other_len); -int8_t ICU4XLocale_total_cmp_(const Locale* self, const Locale* other); +int8_t ICU4XLocale_compare_to(const Locale* self, const Locale* other); void ICU4XLocale_destroy(Locale* self); diff --git a/ffi/capi/bindings/c/ReorderedIndexMap.h b/ffi/capi/bindings/c/ReorderedIndexMap.h index 5507f814bd0..590b1beac5b 100644 --- a/ffi/capi/bindings/c/ReorderedIndexMap.h +++ b/ffi/capi/bindings/c/ReorderedIndexMap.h @@ -15,7 +15,7 @@ -diplomat::capi::DiplomatUsizeView ICU4XReorderedIndexMap_as_slice(const ReorderedIndexMap* self); +DiplomatUsizeView ICU4XReorderedIndexMap_as_slice(const ReorderedIndexMap* self); size_t ICU4XReorderedIndexMap_len(const ReorderedIndexMap* self); diff --git a/ffi/capi/bindings/cpp/Collator.hpp b/ffi/capi/bindings/cpp/Collator.hpp index 03c7938a313..aa60a10c037 100644 --- a/ffi/capi/bindings/cpp/Collator.hpp +++ b/ffi/capi/bindings/cpp/Collator.hpp @@ -24,9 +24,9 @@ namespace capi { typedef struct ICU4XCollator_create_v1_result {union {diplomat::capi::Collator* ok; diplomat::capi::DataError err;}; bool is_ok;} ICU4XCollator_create_v1_result; ICU4XCollator_create_v1_result ICU4XCollator_create_v1(const diplomat::capi::DataProvider* provider, const diplomat::capi::Locale* locale, diplomat::capi::CollatorOptionsV1 options); - int8_t ICU4XCollator_compare_utf16_(const diplomat::capi::Collator* self, const char16_t* left_data, size_t left_len, const char16_t* right_data, size_t right_len); + int8_t ICU4XCollator_compare_utf16(const diplomat::capi::Collator* self, const char16_t* left_data, size_t left_len, const char16_t* right_data, size_t right_len); - int8_t ICU4XCollator_compare_(const diplomat::capi::Collator* self, const char* left_data, size_t left_len, const char* right_data, size_t right_len); + int8_t ICU4XCollator_compare(const diplomat::capi::Collator* self, const char* left_data, size_t left_len, const char* right_data, size_t right_len); diplomat::capi::CollatorResolvedOptionsV1 ICU4XCollator_resolved_options(const diplomat::capi::Collator* self); @@ -45,7 +45,7 @@ inline diplomat::result, DataError> Collator::create_v } inline int8_t Collator::compare16(std::u16string_view left, std::u16string_view right) const { - auto result = diplomat::capi::ICU4XCollator_compare_utf16_(this->AsFFI(), + auto result = diplomat::capi::ICU4XCollator_compare_utf16(this->AsFFI(), left.data(), left.size(), right.data(), @@ -54,7 +54,7 @@ inline int8_t Collator::compare16(std::u16string_view left, std::u16string_view } inline int8_t Collator::compare(std::string_view left, std::string_view right) const { - auto result = diplomat::capi::ICU4XCollator_compare_(this->AsFFI(), + auto result = diplomat::capi::ICU4XCollator_compare(this->AsFFI(), left.data(), left.size(), right.data(), diff --git a/ffi/capi/bindings/cpp/Locale.d.hpp b/ffi/capi/bindings/cpp/Locale.d.hpp index 6076ddf19f8..103c9e5f81e 100644 --- a/ffi/capi/bindings/cpp/Locale.d.hpp +++ b/ffi/capi/bindings/cpp/Locale.d.hpp @@ -49,9 +49,9 @@ class Locale { inline bool normalizing_eq(std::string_view other) const; - inline int8_t strict_cmp_(std::string_view other) const; + inline int8_t compare_to_string(std::string_view other) const; - inline int8_t total_cmp_(const Locale& other) const; + inline int8_t compare_to(const Locale& other) const; inline const diplomat::capi::Locale* AsFFI() const; inline diplomat::capi::Locale* AsFFI(); diff --git a/ffi/capi/bindings/cpp/Locale.hpp b/ffi/capi/bindings/cpp/Locale.hpp index 6a63f31e8a0..817fad19637 100644 --- a/ffi/capi/bindings/cpp/Locale.hpp +++ b/ffi/capi/bindings/cpp/Locale.hpp @@ -53,9 +53,9 @@ namespace capi { bool ICU4XLocale_normalizing_eq(const diplomat::capi::Locale* self, const char* other_data, size_t other_len); - int8_t ICU4XLocale_strict_cmp_(const diplomat::capi::Locale* self, const char* other_data, size_t other_len); + int8_t ICU4XLocale_compare_to_string(const diplomat::capi::Locale* self, const char* other_data, size_t other_len); - int8_t ICU4XLocale_total_cmp_(const diplomat::capi::Locale* self, const diplomat::capi::Locale* other); + int8_t ICU4XLocale_compare_to(const diplomat::capi::Locale* self, const diplomat::capi::Locale* other); void ICU4XLocale_destroy(Locale* self); @@ -167,15 +167,15 @@ inline bool Locale::normalizing_eq(std::string_view other) const { return result; } -inline int8_t Locale::strict_cmp_(std::string_view other) const { - auto result = diplomat::capi::ICU4XLocale_strict_cmp_(this->AsFFI(), +inline int8_t Locale::compare_to_string(std::string_view other) const { + auto result = diplomat::capi::ICU4XLocale_compare_to_string(this->AsFFI(), other.data(), other.size()); return result; } -inline int8_t Locale::total_cmp_(const Locale& other) const { - auto result = diplomat::capi::ICU4XLocale_total_cmp_(this->AsFFI(), +inline int8_t Locale::compare_to(const Locale& other) const { + auto result = diplomat::capi::ICU4XLocale_compare_to(this->AsFFI(), other.AsFFI()); return result; } diff --git a/ffi/capi/bindings/cpp/ReorderedIndexMap.hpp b/ffi/capi/bindings/cpp/ReorderedIndexMap.hpp index 2b59a543fb7..f276f93d911 100644 --- a/ffi/capi/bindings/cpp/ReorderedIndexMap.hpp +++ b/ffi/capi/bindings/cpp/ReorderedIndexMap.hpp @@ -16,7 +16,7 @@ namespace diplomat { namespace capi { extern "C" { - DiplomatUsizeView ICU4XReorderedIndexMap_as_slice(const diplomat::capi::ReorderedIndexMap* self); + diplomat::capi::DiplomatUsizeView ICU4XReorderedIndexMap_as_slice(const diplomat::capi::ReorderedIndexMap* self); size_t ICU4XReorderedIndexMap_len(const diplomat::capi::ReorderedIndexMap* self); diff --git a/ffi/capi/bindings/cpp/UnitsConverter.d.hpp b/ffi/capi/bindings/cpp/UnitsConverter.d.hpp index 72dd1e41de0..f002d17be45 100644 --- a/ffi/capi/bindings/cpp/UnitsConverter.d.hpp +++ b/ffi/capi/bindings/cpp/UnitsConverter.d.hpp @@ -19,7 +19,7 @@ namespace capi { class UnitsConverter { public: - inline double convert_f64(double value) const; + inline double convert_double(double value) const; inline std::unique_ptr clone() const; diff --git a/ffi/capi/bindings/cpp/UnitsConverter.hpp b/ffi/capi/bindings/cpp/UnitsConverter.hpp index 54dab1eae18..9b831e24db0 100644 --- a/ffi/capi/bindings/cpp/UnitsConverter.hpp +++ b/ffi/capi/bindings/cpp/UnitsConverter.hpp @@ -27,7 +27,7 @@ namespace capi { } // namespace capi } // namespace -inline double UnitsConverter::convert_f64(double value) const { +inline double UnitsConverter::convert_double(double value) const { auto result = diplomat::capi::ICU4XUnitsConverter_convert_f64(this->AsFFI(), value); return result; diff --git a/ffi/capi/bindings/dart/Collator.g.dart b/ffi/capi/bindings/dart/Collator.g.dart index 42dff840476..0855fda5761 100644 --- a/ffi/capi/bindings/dart/Collator.g.dart +++ b/ffi/capi/bindings/dart/Collator.g.dart @@ -47,7 +47,7 @@ final class Collator implements ffi.Finalizable { final temp = ffi2.Arena(); final leftView = left.utf16View; final rightView = right.utf16View; - final result = _ICU4XCollator_compare_utf16_(_ffi, leftView.allocIn(temp), leftView.length, rightView.allocIn(temp), rightView.length); + final result = _ICU4XCollator_compare_utf16(_ffi, leftView.allocIn(temp), leftView.length, rightView.allocIn(temp), rightView.length); temp.releaseAll(); return result; } @@ -73,10 +73,10 @@ external void _ICU4XCollator_destroy(ffi.Pointer self); // ignore: non_constant_identifier_names external _ResultOpaqueInt32 _ICU4XCollator_create_v1(ffi.Pointer provider, ffi.Pointer locale, _CollatorOptionsFfi options); -@meta.ResourceIdentifier('ICU4XCollator_compare_utf16_') -@ffi.Native, ffi.Pointer, ffi.Size, ffi.Pointer, ffi.Size)>(isLeaf: true, symbol: 'ICU4XCollator_compare_utf16_') +@meta.ResourceIdentifier('ICU4XCollator_compare_utf16') +@ffi.Native, ffi.Pointer, ffi.Size, ffi.Pointer, ffi.Size)>(isLeaf: true, symbol: 'ICU4XCollator_compare_utf16') // ignore: non_constant_identifier_names -external int _ICU4XCollator_compare_utf16_(ffi.Pointer self, ffi.Pointer leftData, int leftLength, ffi.Pointer rightData, int rightLength); +external int _ICU4XCollator_compare_utf16(ffi.Pointer self, ffi.Pointer leftData, int leftLength, ffi.Pointer rightData, int rightLength); @meta.ResourceIdentifier('ICU4XCollator_resolved_options') @ffi.Native<_ResolvedCollatorOptionsFfi Function(ffi.Pointer)>(isLeaf: true, symbol: 'ICU4XCollator_resolved_options') diff --git a/ffi/capi/bindings/dart/FixedDecimal.g.dart b/ffi/capi/bindings/dart/FixedDecimal.g.dart index fe94f35a169..80c45bdfecd 100644 --- a/ffi/capi/bindings/dart/FixedDecimal.g.dart +++ b/ffi/capi/bindings/dart/FixedDecimal.g.dart @@ -68,7 +68,7 @@ final class FixedDecimal implements ffi.Finalizable { /// See the [Rust documentation for `FloatPrecision`](https://docs.rs/fixed_decimal/latest/fixed_decimal/enum.FloatPrecision.html) for more information. /// /// Throws [FixedDecimalLimitError] on failure. - factory FixedDecimal.fromDoubleWithDoublePrecision(double f) { + factory FixedDecimal.fromDoubleWithFloatingPrecision(double f) { final result = _ICU4XFixedDecimal_create_from_f64_with_floating_precision(f); if (!result.isOk) { throw FixedDecimalLimitError.values[result.union.err]; diff --git a/ffi/capi/bindings/dart/Locale.g.dart b/ffi/capi/bindings/dart/Locale.g.dart index 34e214ca0ff..7cd792dc2bd 100644 --- a/ffi/capi/bindings/dart/Locale.g.dart +++ b/ffi/capi/bindings/dart/Locale.g.dart @@ -208,14 +208,14 @@ final class Locale implements ffi.Finalizable, core.Comparable { int compareToString(String other) { final temp = ffi2.Arena(); final otherView = other.utf8View; - final result = _ICU4XLocale_strict_cmp_(_ffi, otherView.allocIn(temp), otherView.length); + final result = _ICU4XLocale_compare_to_string(_ffi, otherView.allocIn(temp), otherView.length); temp.releaseAll(); return result; } /// See the [Rust documentation for `total_cmp`](https://docs.rs/icu/latest/icu/locale/struct.Locale.html#method.total_cmp) for more information. int compareTo(Locale other) { - final result = _ICU4XLocale_total_cmp_(_ffi, other._ffi); + final result = _ICU4XLocale_compare_to(_ffi, other._ffi); return result; } @@ -300,12 +300,12 @@ external void _ICU4XLocale_to_string(ffi.Pointer self, ffi.Pointer self, ffi.Pointer otherData, int otherLength); -@meta.ResourceIdentifier('ICU4XLocale_strict_cmp_') -@ffi.Native, ffi.Pointer, ffi.Size)>(isLeaf: true, symbol: 'ICU4XLocale_strict_cmp_') +@meta.ResourceIdentifier('ICU4XLocale_compare_to_string') +@ffi.Native, ffi.Pointer, ffi.Size)>(isLeaf: true, symbol: 'ICU4XLocale_compare_to_string') // ignore: non_constant_identifier_names -external int _ICU4XLocale_strict_cmp_(ffi.Pointer self, ffi.Pointer otherData, int otherLength); +external int _ICU4XLocale_compare_to_string(ffi.Pointer self, ffi.Pointer otherData, int otherLength); -@meta.ResourceIdentifier('ICU4XLocale_total_cmp_') -@ffi.Native, ffi.Pointer)>(isLeaf: true, symbol: 'ICU4XLocale_total_cmp_') +@meta.ResourceIdentifier('ICU4XLocale_compare_to') +@ffi.Native, ffi.Pointer)>(isLeaf: true, symbol: 'ICU4XLocale_compare_to') // ignore: non_constant_identifier_names -external int _ICU4XLocale_total_cmp_(ffi.Pointer self, ffi.Pointer other); +external int _ICU4XLocale_compare_to(ffi.Pointer self, ffi.Pointer other); diff --git a/ffi/capi/bindings/dart/LocaleFallbackIterator.g.dart b/ffi/capi/bindings/dart/LocaleFallbackIterator.g.dart index f326235f52c..2619becb2bd 100644 --- a/ffi/capi/bindings/dart/LocaleFallbackIterator.g.dart +++ b/ffi/capi/bindings/dart/LocaleFallbackIterator.g.dart @@ -35,8 +35,6 @@ final class LocaleFallbackIterator implements ffi.Finalizable, core.Iterator - */ - static create(provider: DataProvider): Bidi | never; - - /** - - * Use the data loaded in this object to process a string and calculate bidi information - - * Takes in a Level for the default level, if it is an invalid value it will default to LTR - - * Returns nothing if `text` is invalid UTF-8. - - * See the {@link https://docs.rs/unicode_bidi/latest/unicode_bidi/struct.BidiInfo.html#method.new_with_data_source Rust documentation for `new_with_data_source`} for more information. - */ - for_text(text: string, default_level: u8): BidiInfo | undefined; - - /** - - * Utility function for producing reorderings given a list of levels - - * Produces a map saying which visual index maps to which source index. - - * The levels array must not have values greater than 126 (this is the Bidi maximum explicit depth plus one). Failure to follow this invariant may lead to incorrect results, but is still safe. - - * See the {@link https://docs.rs/unicode_bidi/latest/unicode_bidi/struct.BidiInfo.html#method.reorder_visual Rust documentation for `reorder_visual`} for more information. - */ - reorder_visual(levels: Uint8Array): ReorderedIndexMap; - - /** - - * Check if a Level returned by level_at is an RTL level. - - * Invalid levels (numbers greater than 125) will be assumed LTR - - * See the {@link https://docs.rs/unicode_bidi/latest/unicode_bidi/struct.Level.html#method.is_rtl Rust documentation for `is_rtl`} for more information. - */ - static level_is_rtl(level: u8): boolean; + get ffiValue(): pointer; - /** - * Check if a Level returned by level_at is an LTR level. + static create(provider: DataProvider): Bidi; - * Invalid levels (numbers greater than 125) will be assumed LTR + forText(text: string, defaultLevel: number): BidiInfo; - * See the {@link https://docs.rs/unicode_bidi/latest/unicode_bidi/struct.Level.html#method.is_ltr Rust documentation for `is_ltr`} for more information. - */ - static level_is_ltr(level: u8): boolean; + reorderVisual(levels: Array): ReorderedIndexMap; - /** + static levelIsRtl(level: number): boolean; - * Get a basic RTL Level value + static levelIsLtr(level: number): boolean; - * See the {@link https://docs.rs/unicode_bidi/latest/unicode_bidi/struct.Level.html#method.rtl Rust documentation for `rtl`} for more information. - */ - static level_rtl(): u8; + static levelRtl(): number; - /** + static levelLtr(): number; - * Get a simple LTR Level value + - * See the {@link https://docs.rs/unicode_bidi/latest/unicode_bidi/struct.Level.html#method.ltr Rust documentation for `ltr`} for more information. - */ - static level_ltr(): u8; -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/Bidi.mjs b/ffi/capi/bindings/js/Bidi.mjs index e3f6a57b8cb..fed77528b18 100644 --- a/ffi/capi/bindings/js/Bidi.mjs +++ b/ffi/capi/bindings/js/Bidi.mjs @@ -1,70 +1,138 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" +// generated by diplomat-tool import { BidiInfo } from "./BidiInfo.mjs" -import { DataError_js_to_rust, DataError_rust_to_js } from "./DataError.mjs" +import { DataError } from "./DataError.mjs" +import { DataProvider } from "./DataProvider.mjs" import { ReorderedIndexMap } from "./ReorderedIndexMap.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -const Bidi_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XBidi_destroy(underlying); -}); +/** An ICU4X Bidi object, containing loaded bidi data +* +*See the [Rust documentation for `BidiClassAdapter`](https://docs.rs/icu/latest/icu/properties/bidi/struct.BidiClassAdapter.html) for more information. +*/ + +const Bidi_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XBidi_destroy(ptr); +}); export class Bidi { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - Bidi_box_destroy_registry.register(this, underlying); + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + + constructor(ptr, selfEdge) { + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + Bidi_box_destroy_registry.register(this, this.#ptr); + } + + get ffiValue() { + return this.#ptr; + } + + + static create(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XBidi_create(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new Bidi(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + forText(text, defaultLevel) { + + const textSlice = diplomatRuntime.DiplomatBuf.str8(wasm, text); + + // This lifetime edge depends on lifetimes 'text + let textEdges = [textSlice]; + const result = wasm.ICU4XBidi_for_text_valid_utf8(this.ffiValue, textSlice.ptr, textSlice.size, defaultLevel); + + try { + + return new BidiInfo(result, [], textEdges); + } finally { + + textSlice.garbageCollect(); + + } } - } - static create(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XBidi_create(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new Bidi(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } + reorderVisual(levels) { + + const levelsSlice = diplomatRuntime.DiplomatBuf.slice(wasm, levels, "u8"); + const result = wasm.ICU4XBidi_reorder_visual(this.ffiValue, levelsSlice.ptr, levelsSlice.size); + + try { + + return new ReorderedIndexMap(result, []); + } finally { + + levelsSlice.free(); + + } + } - for_text(arg_text, arg_default_level) { - const buf_arg_text = diplomatRuntime.DiplomatBuf.str8(wasm, arg_text); - const diplomat_out = (() => { - const option_ptr = wasm.ICU4XBidi_for_text(this.underlying, buf_arg_text.ptr, buf_arg_text.size, arg_default_level); - return (option_ptr == 0) ? undefined : new BidiInfo(option_ptr, true, [buf_arg_text]); - })(); - buf_arg_text.garbageCollect(); - return diplomat_out; - } + static levelIsRtl(level) { + const result = wasm.ICU4XBidi_level_is_rtl(level); + + try { + + return result; + } finally { + + } + } - reorder_visual(arg_levels) { - const buf_arg_levels = diplomatRuntime.DiplomatBuf.slice(wasm, arg_levels, "u8"); - const diplomat_out = new ReorderedIndexMap(wasm.ICU4XBidi_reorder_visual(this.underlying, buf_arg_levels.ptr, buf_arg_levels.size), true, []); - buf_arg_levels.free(); - return diplomat_out; - } + static levelIsLtr(level) { + const result = wasm.ICU4XBidi_level_is_ltr(level); + + try { + + return result; + } finally { + + } + } - static level_is_rtl(arg_level) { - return wasm.ICU4XBidi_level_is_rtl(arg_level); - } + static levelRtl() { + const result = wasm.ICU4XBidi_level_rtl(); + + try { + + return result; + } finally { + + } + } - static level_is_ltr(arg_level) { - return wasm.ICU4XBidi_level_is_ltr(arg_level); - } + static levelLtr() { + const result = wasm.ICU4XBidi_level_ltr(); + + try { + + return result; + } finally { + + } + } - static level_rtl() { - return wasm.ICU4XBidi_level_rtl(); - } + - static level_ltr() { - return wasm.ICU4XBidi_level_ltr(); - } -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/BidiDirection.d.ts b/ffi/capi/bindings/js/BidiDirection.d.ts index 99b7721ac85..9ff0cafa515 100644 --- a/ffi/capi/bindings/js/BidiDirection.d.ts +++ b/ffi/capi/bindings/js/BidiDirection.d.ts @@ -1,14 +1,21 @@ +// generated by diplomat-tool +import type { pointer, char } from "./diplomat-runtime.d.ts"; + +// Base enumerator definition +export class BidiDirection { + constructor(value : BidiDirection | string); + + get value() : string; + + get ffiValue() : number; + + static Ltr : BidiDirection; + + static Rtl : BidiDirection; + + static Mixed : BidiDirection; + + + -/** - */ -export enum BidiDirection { - /** - */ - Ltr = 'Ltr', - /** - */ - Rtl = 'Rtl', - /** - */ - Mixed = 'Mixed', } \ No newline at end of file diff --git a/ffi/capi/bindings/js/BidiDirection.mjs b/ffi/capi/bindings/js/BidiDirection.mjs index 51c500d8f76..b23ec13953e 100644 --- a/ffi/capi/bindings/js/BidiDirection.mjs +++ b/ffi/capi/bindings/js/BidiDirection.mjs @@ -1,20 +1,45 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" - -export const BidiDirection_js_to_rust = { - "Ltr": 0, - "Rtl": 1, - "Mixed": 2, -}; - -export const BidiDirection_rust_to_js = { - [0]: "Ltr", - [1]: "Rtl", - [2]: "Mixed", -}; - -export const BidiDirection = { - "Ltr": "Ltr", - "Rtl": "Rtl", - "Mixed": "Mixed", -}; +// generated by diplomat-tool +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; + +// Base enumerator definition +export class BidiDirection { + #value = undefined; + + static values = new Map([ + ["Ltr", 0], + ["Rtl", 1], + ["Mixed", 2] + ]); + constructor(value) { + if (value instanceof BidiDirection) { + this.#value = value.value; + return; + } + + if (BidiDirection.values.has(value)) { + this.#value = value; + return; + } + + throw TypeError(value + " is not a BidiDirection and does not correspond to any of its enumerator values."); + } + + get value() { + return this.#value; + } + + get ffiValue() { + return BidiDirection.values.get(this.#value); + } + + static Ltr = new BidiDirection("Ltr"); + + static Rtl = new BidiDirection("Rtl"); + + static Mixed = new BidiDirection("Mixed"); + + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/BidiInfo.d.ts b/ffi/capi/bindings/js/BidiInfo.d.ts index 8bb52de2208..f2b1521baeb 100644 --- a/ffi/capi/bindings/js/BidiInfo.d.ts +++ b/ffi/capi/bindings/js/BidiInfo.d.ts @@ -1,37 +1,26 @@ -import { u8, usize } from "./diplomat-runtime" -import { BidiParagraph } from "./BidiParagraph"; +// generated by diplomat-tool +import type { BidiParagraph } from "./BidiParagraph" +import type { pointer, char } from "./diplomat-runtime.d.ts"; -/** - * An object containing bidi information for a given string, produced by `for_text()` on `Bidi` - - * See the {@link https://docs.rs/unicode_bidi/latest/unicode_bidi/struct.BidiInfo.html Rust documentation for `BidiInfo`} for more information. - */ +/** An object containing bidi information for a given string, produced by `for_text()` on `Bidi` +* +*See the [Rust documentation for `BidiInfo`](https://docs.rs/unicode_bidi/latest/unicode_bidi/struct.BidiInfo.html) for more information. +*/ export class BidiInfo { + - /** - - * The number of paragraphs contained here - */ - paragraph_count(): usize; + get ffiValue(): pointer; - /** - * Get the nth paragraph, returning `None` if out of bounds - */ - paragraph_at(n: usize): BidiParagraph | undefined; + get paragraphCount(): number; - /** + paragraphAt(n: number): BidiParagraph | null; - * The number of bytes in this full text - */ - size(): usize; + get size(): number; - /** + levelAt(pos: number): number; - * Get the BIDI level at a particular byte index in the full text. This integer is conceptually a `unicode_bidi::Level`, and can be further inspected using the static methods on Bidi. + - * Returns 0 (equivalent to `Level::ltr()`) on error - */ - level_at(pos: usize): u8; -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/BidiInfo.mjs b/ffi/capi/bindings/js/BidiInfo.mjs index 29c44eaf4ba..3eee44aa283 100644 --- a/ffi/capi/bindings/js/BidiInfo.mjs +++ b/ffi/capi/bindings/js/BidiInfo.mjs @@ -1,37 +1,91 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" +// generated by diplomat-tool import { BidiParagraph } from "./BidiParagraph.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -const BidiInfo_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XBidiInfo_destroy(underlying); -}); +/** An object containing bidi information for a given string, produced by `for_text()` on `Bidi` +* +*See the [Rust documentation for `BidiInfo`](https://docs.rs/unicode_bidi/latest/unicode_bidi/struct.BidiInfo.html) for more information. +*/ + +const BidiInfo_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XBidiInfo_destroy(ptr); +}); export class BidiInfo { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - BidiInfo_box_destroy_registry.register(this, underlying); + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + #textEdge = []; + + + constructor(ptr, selfEdge, textEdge) { + + + this.#textEdge = textEdge; + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + BidiInfo_box_destroy_registry.register(this, this.#ptr); + } + + get ffiValue() { + return this.#ptr; + } + + + get paragraphCount() { + const result = wasm.ICU4XBidiInfo_paragraph_count(this.ffiValue); + + try { + + return result; + } finally { + + } } - } - - paragraph_count() { - return wasm.ICU4XBidiInfo_paragraph_count(this.underlying); - } - - paragraph_at(arg_n) { - return (() => { - const option_ptr = wasm.ICU4XBidiInfo_paragraph_at(this.underlying, arg_n); - return (option_ptr == 0) ? undefined : new BidiParagraph(option_ptr, true, [this]); - })(); - } - - size() { - return wasm.ICU4XBidiInfo_size(this.underlying); - } - - level_at(arg_pos) { - return wasm.ICU4XBidiInfo_level_at(this.underlying, arg_pos); - } -} + + paragraphAt(n) { + + // This lifetime edge depends on lifetimes 'text + let textEdges = [this]; + const result = wasm.ICU4XBidiInfo_paragraph_at(this.ffiValue, n); + + try { + + return result == 0 ? null : new BidiParagraph(result, [], textEdges); + } finally { + + } + } + + get size() { + const result = wasm.ICU4XBidiInfo_size(this.ffiValue); + + try { + + return result; + } finally { + + } + } + + levelAt(pos) { + const result = wasm.ICU4XBidiInfo_level_at(this.ffiValue, pos); + + try { + + return result; + } finally { + + } + } + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/BidiParagraph.d.ts b/ffi/capi/bindings/js/BidiParagraph.d.ts index e68ea3bf349..ee6e165f360 100644 --- a/ffi/capi/bindings/js/BidiParagraph.d.ts +++ b/ffi/capi/bindings/js/BidiParagraph.d.ts @@ -1,63 +1,30 @@ -import { u8, usize } from "./diplomat-runtime" -import { BidiDirection } from "./BidiDirection"; +// generated by diplomat-tool +import type { BidiDirection } from "./BidiDirection" +import type { pointer, char } from "./diplomat-runtime.d.ts"; -/** - * Bidi information for a single processed paragraph - */ +/** Bidi information for a single processed paragraph +*/ export class BidiParagraph { + - /** + get ffiValue(): pointer; - * Given a paragraph index `n` within the surrounding text, this sets this object to the paragraph at that index. Returns nothing when out of bounds. - * This is equivalent to calling `paragraph_at()` on `BidiInfo` but doesn't create a new object - */ - set_paragraph_in_text(n: usize): boolean; + setParagraphInText(n: number): boolean; - /** + get direction(): BidiDirection; - * The primary direction of this paragraph + get size(): number; - * See the {@link https://docs.rs/unicode_bidi/latest/unicode_bidi/struct.Paragraph.html#method.level_at Rust documentation for `level_at`} for more information. - */ - direction(): BidiDirection; + get rangeStart(): number; - /** + get rangeEnd(): number; - * The number of bytes in this paragraph + reorderLine(rangeStart: number, rangeEnd: number): string | null; - * See the {@link https://docs.rs/unicode_bidi/latest/unicode_bidi/struct.ParagraphInfo.html#method.len Rust documentation for `len`} for more information. - */ - size(): usize; + levelAt(pos: number): number; - /** + - * The start index of this paragraph within the source text - */ - range_start(): usize; - - /** - - * The end index of this paragraph within the source text - */ - range_end(): usize; - - /** - - * Reorder a line based on display order. The ranges are specified relative to the source text and must be contained within this paragraph's range. - - * See the {@link https://docs.rs/unicode_bidi/latest/unicode_bidi/struct.Paragraph.html#method.level_at Rust documentation for `level_at`} for more information. - */ - reorder_line(range_start: usize, range_end: usize): string | undefined; - - /** - - * Get the BIDI level at a particular byte index in this paragraph. This integer is conceptually a `unicode_bidi::Level`, and can be further inspected using the static methods on Bidi. - - * Returns 0 (equivalent to `Level::ltr()`) on error - - * See the {@link https://docs.rs/unicode_bidi/latest/unicode_bidi/struct.Paragraph.html#method.level_at Rust documentation for `level_at`} for more information. - */ - level_at(pos: usize): u8; -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/BidiParagraph.mjs b/ffi/capi/bindings/js/BidiParagraph.mjs index 79a8aca2ec2..afd5f5da349 100644 --- a/ffi/capi/bindings/js/BidiParagraph.mjs +++ b/ffi/capi/bindings/js/BidiParagraph.mjs @@ -1,51 +1,123 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" -import { BidiDirection_js_to_rust, BidiDirection_rust_to_js } from "./BidiDirection.mjs" +// generated by diplomat-tool +import { BidiDirection } from "./BidiDirection.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -const BidiParagraph_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XBidiParagraph_destroy(underlying); -}); +/** Bidi information for a single processed paragraph +*/ + +const BidiParagraph_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XBidiParagraph_destroy(ptr); +}); export class BidiParagraph { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - BidiParagraph_box_destroy_registry.register(this, underlying); - } - } - - set_paragraph_in_text(arg_n) { - return wasm.ICU4XBidiParagraph_set_paragraph_in_text(this.underlying, arg_n); - } - - direction() { - return BidiDirection_rust_to_js[wasm.ICU4XBidiParagraph_direction(this.underlying)]; - } - - size() { - return wasm.ICU4XBidiParagraph_size(this.underlying); - } - - range_start() { - return wasm.ICU4XBidiParagraph_range_start(this.underlying); - } - - range_end() { - return wasm.ICU4XBidiParagraph_range_end(this.underlying); - } - - reorder_line(arg_range_start, arg_range_end) { - return diplomatRuntime.withDiplomatWrite(wasm, (write) => { - return (() => { - const is_ok = wasm.ICU4XBidiParagraph_reorder_line(this.underlying, arg_range_start, arg_range_end, write) == 1; - if (!is_ok) return; - })(); - }); - } - - level_at(arg_pos) { - return wasm.ICU4XBidiParagraph_level_at(this.underlying, arg_pos); - } -} + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + #infoEdge = []; + + + constructor(ptr, selfEdge, infoEdge) { + + + this.#infoEdge = infoEdge; + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + BidiParagraph_box_destroy_registry.register(this, this.#ptr); + } + + get ffiValue() { + return this.#ptr; + } + + + setParagraphInText(n) { + const result = wasm.ICU4XBidiParagraph_set_paragraph_in_text(this.ffiValue, n); + + try { + + return result; + } finally { + + } + } + + get direction() { + const result = wasm.ICU4XBidiParagraph_direction(this.ffiValue); + + try { + + return BidiDirection[Array.from(BidiDirection.values.keys())[result]]; + } finally { + + } + } + + get size() { + const result = wasm.ICU4XBidiParagraph_size(this.ffiValue); + + try { + + return result; + } finally { + + } + } + + get rangeStart() { + const result = wasm.ICU4XBidiParagraph_range_start(this.ffiValue); + + try { + + return result; + } finally { + + } + } + + get rangeEnd() { + const result = wasm.ICU4XBidiParagraph_range_end(this.ffiValue); + + try { + + return result; + } finally { + + } + } + + reorderLine(rangeStart, rangeEnd) { + + const write = wasm.diplomat_buffer_write_create(0); + const result = wasm.ICU4XBidiParagraph_reorder_line(this.ffiValue, rangeStart, rangeEnd, write); + + try { + + return result == 0 ? null : diplomatRuntime.readString8(wasm, wasm.diplomat_buffer_write_get_bytes(write), wasm.diplomat_buffer_write_len(write)); + } finally { + + wasm.diplomat_buffer_write_destroy(write); + + } + } + + levelAt(pos) { + const result = wasm.ICU4XBidiParagraph_level_at(this.ffiValue, pos); + + try { + + return result; + } finally { + + } + } + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/Calendar.d.ts b/ffi/capi/bindings/js/Calendar.d.ts index 7f3c9cb2bae..99a693fd1fd 100644 --- a/ffi/capi/bindings/js/Calendar.d.ts +++ b/ffi/capi/bindings/js/Calendar.d.ts @@ -1,38 +1,24 @@ -import { FFIError } from "./diplomat-runtime" -import { AnyCalendarKind } from "./AnyCalendarKind"; -import { DataError } from "./DataError"; -import { DataProvider } from "./DataProvider"; -import { Locale } from "./Locale"; +// generated by diplomat-tool +import type { AnyCalendarKind } from "./AnyCalendarKind" +import type { DataProvider } from "./DataProvider" +import type { Locale } from "./Locale" +import type { pointer, char } from "./diplomat-runtime.d.ts"; -/** - * See the {@link https://docs.rs/icu/latest/icu/calendar/enum.AnyCalendar.html Rust documentation for `AnyCalendar`} for more information. - */ +/** See the [Rust documentation for `AnyCalendar`](https://docs.rs/icu/latest/icu/calendar/enum.AnyCalendar.html) for more information. +*/ export class Calendar { + - /** + get ffiValue(): pointer; - * Creates a new {@link Calendar `Calendar`} from the specified date and time. - * See the {@link https://docs.rs/icu/latest/icu/calendar/enum.AnyCalendar.html#method.new_for_locale Rust documentation for `new_for_locale`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static create_for_locale(provider: DataProvider, locale: Locale): Calendar | never; + static createForLocale(provider: DataProvider, locale: Locale): Calendar; - /** + static createForKind(provider: DataProvider, kind: AnyCalendarKind): Calendar; - * Creates a new {@link Calendar `Calendar`} from the specified date and time. + get kind(): AnyCalendarKind; - * See the {@link https://docs.rs/icu/latest/icu/calendar/enum.AnyCalendar.html#method.new Rust documentation for `new`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static create_for_kind(provider: DataProvider, kind: AnyCalendarKind): Calendar | never; + - /** - - * Returns the kind of this calendar - - * See the {@link https://docs.rs/icu/latest/icu/calendar/enum.AnyCalendar.html#method.kind Rust documentation for `kind`} for more information. - */ - kind(): AnyCalendarKind; -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/Calendar.mjs b/ffi/capi/bindings/js/Calendar.mjs index 1dfaa45cebe..dfa2a88534b 100644 --- a/ffi/capi/bindings/js/Calendar.mjs +++ b/ffi/capi/bindings/js/Calendar.mjs @@ -1,57 +1,89 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" -import { AnyCalendarKind_js_to_rust, AnyCalendarKind_rust_to_js } from "./AnyCalendarKind.mjs" -import { DataError_js_to_rust, DataError_rust_to_js } from "./DataError.mjs" +// generated by diplomat-tool +import { AnyCalendarKind } from "./AnyCalendarKind.mjs" +import { DataError } from "./DataError.mjs" +import { DataProvider } from "./DataProvider.mjs" +import { Locale } from "./Locale.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -const Calendar_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XCalendar_destroy(underlying); -}); +/** See the [Rust documentation for `AnyCalendar`](https://docs.rs/icu/latest/icu/calendar/enum.AnyCalendar.html) for more information. +*/ + +const Calendar_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XCalendar_destroy(ptr); +}); export class Calendar { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - Calendar_box_destroy_registry.register(this, underlying); + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + + constructor(ptr, selfEdge) { + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + Calendar_box_destroy_registry.register(this, this.#ptr); } - } - - static create_for_locale(arg_provider, arg_locale) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCalendar_create_for_locale(diplomat_receive_buffer, arg_provider.underlying, arg_locale.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new Calendar(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static create_for_kind(arg_provider, arg_kind) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCalendar_create_for_kind(diplomat_receive_buffer, arg_provider.underlying, AnyCalendarKind_js_to_rust[arg_kind]); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new Calendar(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - kind() { - return AnyCalendarKind_rust_to_js[wasm.ICU4XCalendar_kind(this.underlying)]; - } -} + + get ffiValue() { + return this.#ptr; + } + + + static createForLocale(provider, locale) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCalendar_create_for_locale(diplomat_receive_buffer, provider.ffiValue, locale.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new Calendar(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static createForKind(provider, kind) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCalendar_create_for_kind(diplomat_receive_buffer, provider.ffiValue, kind.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new Calendar(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + get kind() { + const result = wasm.ICU4XCalendar_kind(this.ffiValue); + + try { + + return AnyCalendarKind[Array.from(AnyCalendarKind.values.keys())[result]]; + } finally { + + } + } + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/CalendarError.d.ts b/ffi/capi/bindings/js/CalendarError.d.ts index a8615f36733..4ce52b7b9e4 100644 --- a/ffi/capi/bindings/js/CalendarError.d.ts +++ b/ffi/capi/bindings/js/CalendarError.d.ts @@ -1,19 +1,25 @@ +// generated by diplomat-tool +import type { pointer, char } from "./diplomat-runtime.d.ts"; + +// Base enumerator definition +/** Additional information: [1](https://docs.rs/icu/latest/icu/calendar/struct.RangeError.html), [2](https://docs.rs/icu/latest/icu/calendar/enum.DateError.html) +*/ +export class CalendarError { + constructor(value : CalendarError | string); + + get value() : string; + + get ffiValue() : number; + + static Unknown : CalendarError; + + static OutOfRange : CalendarError; + + static UnknownEra : CalendarError; + + static UnknownMonthCode : CalendarError; + + + -/** - - * Additional information: {@link https://docs.rs/icu/latest/icu/calendar/struct.RangeError.html 1}, {@link https://docs.rs/icu/latest/icu/calendar/enum.DateError.html 2} - */ -export enum CalendarError { - /** - */ - Unknown = 'Unknown', - /** - */ - OutOfRange = 'OutOfRange', - /** - */ - UnknownEra = 'UnknownEra', - /** - */ - UnknownMonthCode = 'UnknownMonthCode', } \ No newline at end of file diff --git a/ffi/capi/bindings/js/CalendarError.mjs b/ffi/capi/bindings/js/CalendarError.mjs index a5191e06b28..e1fa971eb3b 100644 --- a/ffi/capi/bindings/js/CalendarError.mjs +++ b/ffi/capi/bindings/js/CalendarError.mjs @@ -1,23 +1,50 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" - -export const CalendarError_js_to_rust = { - "Unknown": 0, - "OutOfRange": 1, - "UnknownEra": 2, - "UnknownMonthCode": 3, -}; - -export const CalendarError_rust_to_js = { - [0]: "Unknown", - [1]: "OutOfRange", - [2]: "UnknownEra", - [3]: "UnknownMonthCode", -}; - -export const CalendarError = { - "Unknown": "Unknown", - "OutOfRange": "OutOfRange", - "UnknownEra": "UnknownEra", - "UnknownMonthCode": "UnknownMonthCode", -}; +// generated by diplomat-tool +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; + +// Base enumerator definition +/** Additional information: [1](https://docs.rs/icu/latest/icu/calendar/struct.RangeError.html), [2](https://docs.rs/icu/latest/icu/calendar/enum.DateError.html) +*/ +export class CalendarError { + #value = undefined; + + static values = new Map([ + ["Unknown", 0], + ["OutOfRange", 1], + ["UnknownEra", 2], + ["UnknownMonthCode", 3] + ]); + constructor(value) { + if (value instanceof CalendarError) { + this.#value = value.value; + return; + } + + if (CalendarError.values.has(value)) { + this.#value = value; + return; + } + + throw TypeError(value + " is not a CalendarError and does not correspond to any of its enumerator values."); + } + + get value() { + return this.#value; + } + + get ffiValue() { + return CalendarError.values.get(this.#value); + } + + static Unknown = new CalendarError("Unknown"); + + static OutOfRange = new CalendarError("OutOfRange"); + + static UnknownEra = new CalendarError("UnknownEra"); + + static UnknownMonthCode = new CalendarError("UnknownMonthCode"); + + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/CanonicalCombiningClassMap.d.ts b/ffi/capi/bindings/js/CanonicalCombiningClassMap.d.ts index fd361d6768b..f0c1f7fbbec 100644 --- a/ffi/capi/bindings/js/CanonicalCombiningClassMap.d.ts +++ b/ffi/capi/bindings/js/CanonicalCombiningClassMap.d.ts @@ -1,38 +1,22 @@ -import { u8, u32, char } from "./diplomat-runtime" -import { FFIError } from "./diplomat-runtime" -import { DataError } from "./DataError"; -import { DataProvider } from "./DataProvider"; +// generated by diplomat-tool +import type { DataProvider } from "./DataProvider" +import type { pointer, char } from "./diplomat-runtime.d.ts"; -/** - * Lookup of the Canonical_Combining_Class Unicode property - - * See the {@link https://docs.rs/icu/latest/icu/normalizer/properties/struct.CanonicalCombiningClassMap.html Rust documentation for `CanonicalCombiningClassMap`} for more information. - */ +/** Lookup of the Canonical_Combining_Class Unicode property +* +*See the [Rust documentation for `CanonicalCombiningClassMap`](https://docs.rs/icu/latest/icu/normalizer/properties/struct.CanonicalCombiningClassMap.html) for more information. +*/ export class CanonicalCombiningClassMap { + - /** - - * Construct a new CanonicalCombiningClassMap instance for NFC - - * See the {@link https://docs.rs/icu/latest/icu/normalizer/properties/struct.CanonicalCombiningClassMap.html#method.new Rust documentation for `new`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static create(provider: DataProvider): CanonicalCombiningClassMap | never; - - /** + get ffiValue(): pointer; - * See the {@link https://docs.rs/icu/latest/icu/normalizer/properties/struct.CanonicalCombiningClassMap.html#method.get Rust documentation for `get`} for more information. - * Additional information: {@link https://docs.rs/icu/latest/icu/properties/properties/struct.CanonicalCombiningClass.html 1} - */ - get(ch: char): u8; + static create(provider: DataProvider): CanonicalCombiningClassMap; - /** + get(ch: char): number; - * See the {@link https://docs.rs/icu/latest/icu/normalizer/properties/struct.CanonicalCombiningClassMap.html#method.get32 Rust documentation for `get32`} for more information. + - * Additional information: {@link https://docs.rs/icu/latest/icu/properties/properties/struct.CanonicalCombiningClass.html 1} - */ - get32(ch: u32): u8; -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/CanonicalCombiningClassMap.mjs b/ffi/capi/bindings/js/CanonicalCombiningClassMap.mjs index 59ab31d16be..9502cfdefc1 100644 --- a/ffi/capi/bindings/js/CanonicalCombiningClassMap.mjs +++ b/ffi/capi/bindings/js/CanonicalCombiningClassMap.mjs @@ -1,43 +1,70 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" -import { DataError_js_to_rust, DataError_rust_to_js } from "./DataError.mjs" +// generated by diplomat-tool +import { DataError } from "./DataError.mjs" +import { DataProvider } from "./DataProvider.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -const CanonicalCombiningClassMap_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XCanonicalCombiningClassMap_destroy(underlying); -}); +/** Lookup of the Canonical_Combining_Class Unicode property +* +*See the [Rust documentation for `CanonicalCombiningClassMap`](https://docs.rs/icu/latest/icu/normalizer/properties/struct.CanonicalCombiningClassMap.html) for more information. +*/ + +const CanonicalCombiningClassMap_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XCanonicalCombiningClassMap_destroy(ptr); +}); export class CanonicalCombiningClassMap { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - CanonicalCombiningClassMap_box_destroy_registry.register(this, underlying); + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + + constructor(ptr, selfEdge) { + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + CanonicalCombiningClassMap_box_destroy_registry.register(this, this.#ptr); } - } - - static create(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCanonicalCombiningClassMap_create(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CanonicalCombiningClassMap(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - get(arg_ch) { - return wasm.ICU4XCanonicalCombiningClassMap_get(this.underlying, diplomatRuntime.extractCodePoint(arg_ch, 'arg_ch')); - } - - get32(arg_ch) { - return wasm.ICU4XCanonicalCombiningClassMap_get32(this.underlying, arg_ch); - } -} + + get ffiValue() { + return this.#ptr; + } + + + static create(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCanonicalCombiningClassMap_create(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CanonicalCombiningClassMap(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + get(ch) { + const result = wasm.ICU4XCanonicalCombiningClassMap_get(this.ffiValue, diplomatRuntime.extractCodePoint(ch, 'ch')); + + try { + + return result; + } finally { + + } + } + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/CanonicalComposition.d.ts b/ffi/capi/bindings/js/CanonicalComposition.d.ts index 62c752047c3..fd021446390 100644 --- a/ffi/capi/bindings/js/CanonicalComposition.d.ts +++ b/ffi/capi/bindings/js/CanonicalComposition.d.ts @@ -1,32 +1,24 @@ -import { char } from "./diplomat-runtime" -import { FFIError } from "./diplomat-runtime" -import { DataError } from "./DataError"; -import { DataProvider } from "./DataProvider"; +// generated by diplomat-tool +import type { DataProvider } from "./DataProvider" +import type { pointer, char } from "./diplomat-runtime.d.ts"; -/** - * The raw canonical composition operation. - - * Callers should generally use ComposingNormalizer unless they specifically need raw composition operations - - * See the {@link https://docs.rs/icu/latest/icu/normalizer/properties/struct.CanonicalComposition.html Rust documentation for `CanonicalComposition`} for more information. - */ +/** The raw canonical composition operation. +* +*Callers should generally use ComposingNormalizer unless they specifically need raw composition operations +* +*See the [Rust documentation for `CanonicalComposition`](https://docs.rs/icu/latest/icu/normalizer/properties/struct.CanonicalComposition.html) for more information. +*/ export class CanonicalComposition { + - /** + get ffiValue(): pointer; - * Construct a new CanonicalComposition instance for NFC - * See the {@link https://docs.rs/icu/latest/icu/normalizer/properties/struct.CanonicalComposition.html#method.new Rust documentation for `new`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static create(provider: DataProvider): CanonicalComposition | never; + static create(provider: DataProvider): CanonicalComposition; - /** + compose(starter: char, second: char): char; - * Performs canonical composition (including Hangul) on a pair of characters or returns NUL if these characters don’t compose. Composition exclusions are taken into account. + - * See the {@link https://docs.rs/icu/latest/icu/normalizer/properties/struct.CanonicalComposition.html#method.compose Rust documentation for `compose`} for more information. - */ - compose(starter: char, second: char): char; -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/CanonicalComposition.mjs b/ffi/capi/bindings/js/CanonicalComposition.mjs index 467bb7b60fa..3ebbc597196 100644 --- a/ffi/capi/bindings/js/CanonicalComposition.mjs +++ b/ffi/capi/bindings/js/CanonicalComposition.mjs @@ -1,39 +1,72 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" -import { DataError_js_to_rust, DataError_rust_to_js } from "./DataError.mjs" +// generated by diplomat-tool +import { DataError } from "./DataError.mjs" +import { DataProvider } from "./DataProvider.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -const CanonicalComposition_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XCanonicalComposition_destroy(underlying); -}); +/** The raw canonical composition operation. +* +*Callers should generally use ComposingNormalizer unless they specifically need raw composition operations +* +*See the [Rust documentation for `CanonicalComposition`](https://docs.rs/icu/latest/icu/normalizer/properties/struct.CanonicalComposition.html) for more information. +*/ + +const CanonicalComposition_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XCanonicalComposition_destroy(ptr); +}); export class CanonicalComposition { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - CanonicalComposition_box_destroy_registry.register(this, underlying); + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + + constructor(ptr, selfEdge) { + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + CanonicalComposition_box_destroy_registry.register(this, this.#ptr); } - } - - static create(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCanonicalComposition_create(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CanonicalComposition(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - compose(arg_starter, arg_second) { - return wasm.ICU4XCanonicalComposition_compose(this.underlying, diplomatRuntime.extractCodePoint(arg_starter, 'arg_starter'), diplomatRuntime.extractCodePoint(arg_second, 'arg_second')); - } -} + + get ffiValue() { + return this.#ptr; + } + + + static create(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCanonicalComposition_create(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CanonicalComposition(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + compose(starter, second) { + const result = wasm.ICU4XCanonicalComposition_compose(this.ffiValue, diplomatRuntime.extractCodePoint(starter, 'starter'), diplomatRuntime.extractCodePoint(second, 'second')); + + try { + + return result; + } finally { + + } + } + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/CanonicalDecomposition.d.ts b/ffi/capi/bindings/js/CanonicalDecomposition.d.ts index 89d101f9aae..98fa776339f 100644 --- a/ffi/capi/bindings/js/CanonicalDecomposition.d.ts +++ b/ffi/capi/bindings/js/CanonicalDecomposition.d.ts @@ -1,33 +1,25 @@ -import { char } from "./diplomat-runtime" -import { FFIError } from "./diplomat-runtime" -import { DataError } from "./DataError"; -import { DataProvider } from "./DataProvider"; -import { Decomposed } from "./Decomposed"; - -/** - - * The raw (non-recursive) canonical decomposition operation. - - * Callers should generally use DecomposingNormalizer unless they specifically need raw composition operations - - * See the {@link https://docs.rs/icu/latest/icu/normalizer/properties/struct.CanonicalDecomposition.html Rust documentation for `CanonicalDecomposition`} for more information. - */ +// generated by diplomat-tool +import type { DataProvider } from "./DataProvider" +import type { Decomposed } from "./Decomposed" +import type { pointer, char } from "./diplomat-runtime.d.ts"; + + +/** The raw (non-recursive) canonical decomposition operation. +* +*Callers should generally use DecomposingNormalizer unless they specifically need raw composition operations +* +*See the [Rust documentation for `CanonicalDecomposition`](https://docs.rs/icu/latest/icu/normalizer/properties/struct.CanonicalDecomposition.html) for more information. +*/ export class CanonicalDecomposition { + - /** + get ffiValue(): pointer; - * Construct a new CanonicalDecomposition instance for NFC - * See the {@link https://docs.rs/icu/latest/icu/normalizer/properties/struct.CanonicalDecomposition.html#method.new Rust documentation for `new`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static create(provider: DataProvider): CanonicalDecomposition | never; + static create(provider: DataProvider): CanonicalDecomposition; - /** + decompose(c: char): Decomposed; - * Performs non-recursive canonical decomposition (including for Hangul). + - * See the {@link https://docs.rs/icu/latest/icu/normalizer/properties/struct.CanonicalDecomposition.html#method.decompose Rust documentation for `decompose`} for more information. - */ - decompose(c: char): Decomposed; -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/CanonicalDecomposition.mjs b/ffi/capi/bindings/js/CanonicalDecomposition.mjs index 3b13f9a03f3..e1cae30740f 100644 --- a/ffi/capi/bindings/js/CanonicalDecomposition.mjs +++ b/ffi/capi/bindings/js/CanonicalDecomposition.mjs @@ -1,46 +1,77 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" -import { DataError_js_to_rust, DataError_rust_to_js } from "./DataError.mjs" +// generated by diplomat-tool +import { DataError } from "./DataError.mjs" +import { DataProvider } from "./DataProvider.mjs" import { Decomposed } from "./Decomposed.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -const CanonicalDecomposition_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XCanonicalDecomposition_destroy(underlying); -}); +/** The raw (non-recursive) canonical decomposition operation. +* +*Callers should generally use DecomposingNormalizer unless they specifically need raw composition operations +* +*See the [Rust documentation for `CanonicalDecomposition`](https://docs.rs/icu/latest/icu/normalizer/properties/struct.CanonicalDecomposition.html) for more information. +*/ + +const CanonicalDecomposition_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XCanonicalDecomposition_destroy(ptr); +}); export class CanonicalDecomposition { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - CanonicalDecomposition_box_destroy_registry.register(this, underlying); + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + + constructor(ptr, selfEdge) { + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + CanonicalDecomposition_box_destroy_registry.register(this, this.#ptr); } - } - - static create(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCanonicalDecomposition_create(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CanonicalDecomposition(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - decompose(arg_c) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(8, 4); - wasm.ICU4XCanonicalDecomposition_decompose(diplomat_receive_buffer, this.underlying, diplomatRuntime.extractCodePoint(arg_c, 'arg_c')); - const out = new Decomposed(diplomat_receive_buffer); - wasm.diplomat_free(diplomat_receive_buffer, 8, 4); - return out; - })(); - } -} + + get ffiValue() { + return this.#ptr; + } + + + static create(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCanonicalDecomposition_create(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CanonicalDecomposition(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + decompose(c) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(8, 4); + const result = wasm.ICU4XCanonicalDecomposition_decompose(diplomat_receive_buffer, this.ffiValue, diplomatRuntime.extractCodePoint(c, 'c')); + + try { + + return new Decomposed(diplomat_receive_buffer); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 8, 4); + + } + } + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/CaseMapCloser.d.ts b/ffi/capi/bindings/js/CaseMapCloser.d.ts index 44ef9876769..cea84b6aafe 100644 --- a/ffi/capi/bindings/js/CaseMapCloser.d.ts +++ b/ffi/capi/bindings/js/CaseMapCloser.d.ts @@ -1,39 +1,23 @@ -import { char } from "./diplomat-runtime" -import { FFIError } from "./diplomat-runtime" -import { CodePointSetBuilder } from "./CodePointSetBuilder"; -import { DataError } from "./DataError"; -import { DataProvider } from "./DataProvider"; +// generated by diplomat-tool +import type { CodePointSetBuilder } from "./CodePointSetBuilder" +import type { DataProvider } from "./DataProvider" +import type { pointer, char } from "./diplomat-runtime.d.ts"; -/** - * See the {@link https://docs.rs/icu/latest/icu/casemap/struct.CaseMapCloser.html Rust documentation for `CaseMapCloser`} for more information. - */ +/** See the [Rust documentation for `CaseMapCloser`](https://docs.rs/icu/latest/icu/casemap/struct.CaseMapCloser.html) for more information. +*/ export class CaseMapCloser { + - /** + get ffiValue(): pointer; - * Construct a new CaseMapper instance - * See the {@link https://docs.rs/icu/latest/icu/casemap/struct.CaseMapCloser.html#method.new Rust documentation for `new`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static create(provider: DataProvider): CaseMapCloser | never; + static create(provider: DataProvider): CaseMapCloser; - /** + addCaseClosureTo(c: char, builder: CodePointSetBuilder): void; - * Adds all simple case mappings and the full case folding for `c` to `builder`. Also adds special case closure mappings. + addStringCaseClosureTo(s: string, builder: CodePointSetBuilder): boolean; - * See the {@link https://docs.rs/icu/latest/icu/casemap/struct.CaseMapCloser.html#method.add_case_closure_to Rust documentation for `add_case_closure_to`} for more information. - */ - add_case_closure_to(c: char, builder: CodePointSetBuilder): void; + - /** - - * Finds all characters and strings which may casemap to `s` as their full case folding string and adds them to the set. - - * Returns true if the string was found - - * See the {@link https://docs.rs/icu/latest/icu/casemap/struct.CaseMapCloser.html#method.add_string_case_closure_to Rust documentation for `add_string_case_closure_to`} for more information. - */ - add_string_case_closure_to(s: string, builder: CodePointSetBuilder): boolean; -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/CaseMapCloser.mjs b/ffi/capi/bindings/js/CaseMapCloser.mjs index bbe6a85d3b2..ed4f852f40c 100644 --- a/ffi/capi/bindings/js/CaseMapCloser.mjs +++ b/ffi/capi/bindings/js/CaseMapCloser.mjs @@ -1,46 +1,83 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" -import { DataError_js_to_rust, DataError_rust_to_js } from "./DataError.mjs" +// generated by diplomat-tool +import { CodePointSetBuilder } from "./CodePointSetBuilder.mjs" +import { DataError } from "./DataError.mjs" +import { DataProvider } from "./DataProvider.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -const CaseMapCloser_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XCaseMapCloser_destroy(underlying); -}); +/** See the [Rust documentation for `CaseMapCloser`](https://docs.rs/icu/latest/icu/casemap/struct.CaseMapCloser.html) for more information. +*/ + +const CaseMapCloser_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XCaseMapCloser_destroy(ptr); +}); export class CaseMapCloser { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - CaseMapCloser_box_destroy_registry.register(this, underlying); + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + + constructor(ptr, selfEdge) { + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + CaseMapCloser_box_destroy_registry.register(this, this.#ptr); } - } - - static create(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCaseMapCloser_create(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CaseMapCloser(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - add_case_closure_to(arg_c, arg_builder) { - wasm.ICU4XCaseMapCloser_add_case_closure_to(this.underlying, diplomatRuntime.extractCodePoint(arg_c, 'arg_c'), arg_builder.underlying); - } - - add_string_case_closure_to(arg_s, arg_builder) { - const buf_arg_s = diplomatRuntime.DiplomatBuf.str8(wasm, arg_s); - const diplomat_out = wasm.ICU4XCaseMapCloser_add_string_case_closure_to(this.underlying, buf_arg_s.ptr, buf_arg_s.size, arg_builder.underlying); - buf_arg_s.free(); - return diplomat_out; - } -} + + get ffiValue() { + return this.#ptr; + } + + + static create(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCaseMapCloser_create(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CaseMapCloser(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + addCaseClosureTo(c, builder) { + wasm.ICU4XCaseMapCloser_add_case_closure_to(this.ffiValue, diplomatRuntime.extractCodePoint(c, 'c'), builder.ffiValue); + + try { + + } finally { + + } + } + + addStringCaseClosureTo(s, builder) { + + const sSlice = diplomatRuntime.DiplomatBuf.str8(wasm, s); + const result = wasm.ICU4XCaseMapCloser_add_string_case_closure_to(this.ffiValue, sSlice.ptr, sSlice.size, builder.ffiValue); + + try { + + return result; + } finally { + + sSlice.free(); + + } + } + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/CaseMapper.d.ts b/ffi/capi/bindings/js/CaseMapper.d.ts index 384f3f12ce8..7765a5a4593 100644 --- a/ffi/capi/bindings/js/CaseMapper.d.ts +++ b/ffi/capi/bindings/js/CaseMapper.d.ts @@ -1,129 +1,43 @@ -import { char } from "./diplomat-runtime" -import { FFIError } from "./diplomat-runtime" -import { CodePointSetBuilder } from "./CodePointSetBuilder"; -import { DataError } from "./DataError"; -import { DataProvider } from "./DataProvider"; -import { Locale } from "./Locale"; -import { TitlecaseOptionsV1 } from "./TitlecaseOptionsV1"; - -/** - - * See the {@link https://docs.rs/icu/latest/icu/casemap/struct.CaseMapper.html Rust documentation for `CaseMapper`} for more information. - */ -export class CaseMapper { - - /** - - * Construct a new CaseMapper instance - - * See the {@link https://docs.rs/icu/latest/icu/casemap/struct.CaseMapper.html#method.new Rust documentation for `new`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static create(provider: DataProvider): CaseMapper | never; - - /** - - * Returns the full lowercase mapping of the given string - - * See the {@link https://docs.rs/icu/latest/icu/casemap/struct.CaseMapper.html#method.lowercase Rust documentation for `lowercase`} for more information. - */ - lowercase(s: string, locale: Locale): string; - - /** - - * Returns the full uppercase mapping of the given string - - * See the {@link https://docs.rs/icu/latest/icu/casemap/struct.CaseMapper.html#method.uppercase Rust documentation for `uppercase`} for more information. - */ - uppercase(s: string, locale: Locale): string; - - /** - - * Returns the full titlecase mapping of the given string, performing head adjustment without loading additional data. (if head adjustment is enabled in the options) - - * The `v1` refers to the version of the options struct, which may change as we add more options - - * See the {@link https://docs.rs/icu/latest/icu/casemap/struct.CaseMapper.html#method.titlecase_segment_with_only_case_data Rust documentation for `titlecase_segment_with_only_case_data`} for more information. - */ - titlecase_segment_with_only_case_data_v1(s: string, locale: Locale, options: TitlecaseOptionsV1): string; - - /** +// generated by diplomat-tool +import type { CodePointSetBuilder } from "./CodePointSetBuilder" +import type { DataProvider } from "./DataProvider" +import type { Locale } from "./Locale" +import type { TitlecaseOptions } from "./TitlecaseOptions" +import type { pointer, char } from "./diplomat-runtime.d.ts"; - * Case-folds the characters in the given string - * See the {@link https://docs.rs/icu/latest/icu/casemap/struct.CaseMapper.html#method.fold Rust documentation for `fold`} for more information. - */ - fold(s: string): string; - - /** - - * Case-folds the characters in the given string using Turkic (T) mappings for dotted/dotless I. - - * See the {@link https://docs.rs/icu/latest/icu/casemap/struct.CaseMapper.html#method.fold_turkic Rust documentation for `fold_turkic`} for more information. - */ - fold_turkic(s: string): string; - - /** - - * Adds all simple case mappings and the full case folding for `c` to `builder`. Also adds special case closure mappings. - - * In other words, this adds all characters that this casemaps to, as well as all characters that may casemap to this one. - - * Note that since CodePointSetBuilder does not contain strings, this will ignore string mappings. - - * Identical to the similarly named method on `CaseMapCloser`, use that if you plan on using string case closure mappings too. - - * See the {@link https://docs.rs/icu/latest/icu/casemap/struct.CaseMapper.html#method.add_case_closure_to Rust documentation for `add_case_closure_to`} for more information. - */ - add_case_closure_to(c: char, builder: CodePointSetBuilder): void; - - /** - - * Returns the simple lowercase mapping of the given character. - - * This function only implements simple and common mappings. Full mappings, which can map one char to a string, are not included. For full mappings, use `CaseMapper::lowercase`. - - * See the {@link https://docs.rs/icu/latest/icu/casemap/struct.CaseMapper.html#method.simple_lowercase Rust documentation for `simple_lowercase`} for more information. - */ - simple_lowercase(ch: char): char; +/** See the [Rust documentation for `CaseMapper`](https://docs.rs/icu/latest/icu/casemap/struct.CaseMapper.html) for more information. +*/ +export class CaseMapper { + - /** + get ffiValue(): pointer; - * Returns the simple uppercase mapping of the given character. - * This function only implements simple and common mappings. Full mappings, which can map one char to a string, are not included. For full mappings, use `CaseMapper::uppercase`. + static create(provider: DataProvider): CaseMapper; - * See the {@link https://docs.rs/icu/latest/icu/casemap/struct.CaseMapper.html#method.simple_uppercase Rust documentation for `simple_uppercase`} for more information. - */ - simple_uppercase(ch: char): char; + lowercase(s: string, locale: Locale): string; - /** + uppercase(s: string, locale: Locale): string; - * Returns the simple titlecase mapping of the given character. + titlecaseSegmentWithOnlyCaseData(s: string, locale: Locale, options: TitlecaseOptions): string; - * This function only implements simple and common mappings. Full mappings, which can map one char to a string, are not included. For full mappings, use `CaseMapper::titlecase_segment`. + fold(s: string): string; - * See the {@link https://docs.rs/icu/latest/icu/casemap/struct.CaseMapper.html#method.simple_titlecase Rust documentation for `simple_titlecase`} for more information. - */ - simple_titlecase(ch: char): char; + foldTurkic(s: string): string; - /** + addCaseClosureTo(c: char, builder: CodePointSetBuilder): void; - * Returns the simple casefolding of the given character. + simpleLowercase(ch: char): char; - * This function only implements simple folding. For full folding, use `CaseMapper::fold`. + simpleUppercase(ch: char): char; - * See the {@link https://docs.rs/icu/latest/icu/casemap/struct.CaseMapper.html#method.simple_fold Rust documentation for `simple_fold`} for more information. - */ - simple_fold(ch: char): char; + simpleTitlecase(ch: char): char; - /** + simpleFold(ch: char): char; - * Returns the simple casefolding of the given character in the Turkic locale + simpleFoldTurkic(ch: char): char; - * This function only implements simple folding. For full folding, use `CaseMapper::fold_turkic`. + - * See the {@link https://docs.rs/icu/latest/icu/casemap/struct.CaseMapper.html#method.simple_fold_turkic Rust documentation for `simple_fold_turkic`} for more information. - */ - simple_fold_turkic(ch: char): char; -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/CaseMapper.mjs b/ffi/capi/bindings/js/CaseMapper.mjs index c230891c742..1148fa23de5 100644 --- a/ffi/capi/bindings/js/CaseMapper.mjs +++ b/ffi/capi/bindings/js/CaseMapper.mjs @@ -1,108 +1,226 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" -import { DataError_js_to_rust, DataError_rust_to_js } from "./DataError.mjs" -import { LeadingAdjustment_js_to_rust, LeadingAdjustment_rust_to_js } from "./LeadingAdjustment.mjs" -import { TrailingCase_js_to_rust, TrailingCase_rust_to_js } from "./TrailingCase.mjs" - -const CaseMapper_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XCaseMapper_destroy(underlying); -}); +// generated by diplomat-tool +import { CodePointSetBuilder } from "./CodePointSetBuilder.mjs" +import { DataError } from "./DataError.mjs" +import { DataProvider } from "./DataProvider.mjs" +import { Locale } from "./Locale.mjs" +import { TitlecaseOptions } from "./TitlecaseOptions.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; + + +/** See the [Rust documentation for `CaseMapper`](https://docs.rs/icu/latest/icu/casemap/struct.CaseMapper.html) for more information. +*/ +const CaseMapper_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XCaseMapper_destroy(ptr); +}); export class CaseMapper { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - CaseMapper_box_destroy_registry.register(this, underlying); + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + + constructor(ptr, selfEdge) { + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + CaseMapper_box_destroy_registry.register(this, this.#ptr); + } + + get ffiValue() { + return this.#ptr; + } + + + static create(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCaseMapper_create(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CaseMapper(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + lowercase(s, locale) { + + const sSlice = diplomatRuntime.DiplomatBuf.str8(wasm, s); + + const write = wasm.diplomat_buffer_write_create(0); + wasm.ICU4XCaseMapper_lowercase(this.ffiValue, sSlice.ptr, sSlice.size, locale.ffiValue, write); + + try { + + return diplomatRuntime.readString8(wasm, wasm.diplomat_buffer_write_get_bytes(write), wasm.diplomat_buffer_write_len(write)); + } finally { + + sSlice.free(); + + wasm.diplomat_buffer_write_destroy(write); + + } + } + + uppercase(s, locale) { + + const sSlice = diplomatRuntime.DiplomatBuf.str8(wasm, s); + + const write = wasm.diplomat_buffer_write_create(0); + wasm.ICU4XCaseMapper_uppercase(this.ffiValue, sSlice.ptr, sSlice.size, locale.ffiValue, write); + + try { + + return diplomatRuntime.readString8(wasm, wasm.diplomat_buffer_write_get_bytes(write), wasm.diplomat_buffer_write_len(write)); + } finally { + + sSlice.free(); + + wasm.diplomat_buffer_write_destroy(write); + + } + } + + titlecaseSegmentWithOnlyCaseData(s, locale, options) { + + const sSlice = diplomatRuntime.DiplomatBuf.str8(wasm, s); + + let slice_cleanup_callbacks = []; + + const write = wasm.diplomat_buffer_write_create(0); + wasm.ICU4XCaseMapper_titlecase_segment_with_only_case_data_v1(this.ffiValue, sSlice.ptr, sSlice.size, locale.ffiValue, ...options._intoFFI(slice_cleanup_callbacks, {}), write); + + try { + + return diplomatRuntime.readString8(wasm, wasm.diplomat_buffer_write_get_bytes(write), wasm.diplomat_buffer_write_len(write)); + } finally { + + for (let cleanup of slice_cleanup_callbacks) { + cleanup(); + } + + sSlice.free(); + + wasm.diplomat_buffer_write_destroy(write); + + } + } + + fold(s) { + + const sSlice = diplomatRuntime.DiplomatBuf.str8(wasm, s); + + const write = wasm.diplomat_buffer_write_create(0); + wasm.ICU4XCaseMapper_fold(this.ffiValue, sSlice.ptr, sSlice.size, write); + + try { + + return diplomatRuntime.readString8(wasm, wasm.diplomat_buffer_write_get_bytes(write), wasm.diplomat_buffer_write_len(write)); + } finally { + + sSlice.free(); + + wasm.diplomat_buffer_write_destroy(write); + + } + } + + foldTurkic(s) { + + const sSlice = diplomatRuntime.DiplomatBuf.str8(wasm, s); + + const write = wasm.diplomat_buffer_write_create(0); + wasm.ICU4XCaseMapper_fold_turkic(this.ffiValue, sSlice.ptr, sSlice.size, write); + + try { + + return diplomatRuntime.readString8(wasm, wasm.diplomat_buffer_write_get_bytes(write), wasm.diplomat_buffer_write_len(write)); + } finally { + + sSlice.free(); + + wasm.diplomat_buffer_write_destroy(write); + + } + } + + addCaseClosureTo(c, builder) { + wasm.ICU4XCaseMapper_add_case_closure_to(this.ffiValue, diplomatRuntime.extractCodePoint(c, 'c'), builder.ffiValue); + + try { + + } finally { + + } + } + + simpleLowercase(ch) { + const result = wasm.ICU4XCaseMapper_simple_lowercase(this.ffiValue, diplomatRuntime.extractCodePoint(ch, 'ch')); + + try { + + return result; + } finally { + + } + } + + simpleUppercase(ch) { + const result = wasm.ICU4XCaseMapper_simple_uppercase(this.ffiValue, diplomatRuntime.extractCodePoint(ch, 'ch')); + + try { + + return result; + } finally { + + } } - } - - static create(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCaseMapper_create(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CaseMapper(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - lowercase(arg_s, arg_locale) { - const buf_arg_s = diplomatRuntime.DiplomatBuf.str8(wasm, arg_s); - const diplomat_out = diplomatRuntime.withDiplomatWrite(wasm, (write) => { - return wasm.ICU4XCaseMapper_lowercase(this.underlying, buf_arg_s.ptr, buf_arg_s.size, arg_locale.underlying, write); - }); - buf_arg_s.free(); - return diplomat_out; - } - - uppercase(arg_s, arg_locale) { - const buf_arg_s = diplomatRuntime.DiplomatBuf.str8(wasm, arg_s); - const diplomat_out = diplomatRuntime.withDiplomatWrite(wasm, (write) => { - return wasm.ICU4XCaseMapper_uppercase(this.underlying, buf_arg_s.ptr, buf_arg_s.size, arg_locale.underlying, write); - }); - buf_arg_s.free(); - return diplomat_out; - } - - titlecase_segment_with_only_case_data_v1(arg_s, arg_locale, arg_options) { - const buf_arg_s = diplomatRuntime.DiplomatBuf.str8(wasm, arg_s); - const field_leading_adjustment_arg_options = arg_options["leading_adjustment"]; - const field_trailing_case_arg_options = arg_options["trailing_case"]; - const diplomat_out = diplomatRuntime.withDiplomatWrite(wasm, (write) => { - return wasm.ICU4XCaseMapper_titlecase_segment_with_only_case_data_v1(this.underlying, buf_arg_s.ptr, buf_arg_s.size, arg_locale.underlying, LeadingAdjustment_js_to_rust[field_leading_adjustment_arg_options], TrailingCase_js_to_rust[field_trailing_case_arg_options], write); - }); - buf_arg_s.free(); - return diplomat_out; - } - - fold(arg_s) { - const buf_arg_s = diplomatRuntime.DiplomatBuf.str8(wasm, arg_s); - const diplomat_out = diplomatRuntime.withDiplomatWrite(wasm, (write) => { - return wasm.ICU4XCaseMapper_fold(this.underlying, buf_arg_s.ptr, buf_arg_s.size, write); - }); - buf_arg_s.free(); - return diplomat_out; - } - - fold_turkic(arg_s) { - const buf_arg_s = diplomatRuntime.DiplomatBuf.str8(wasm, arg_s); - const diplomat_out = diplomatRuntime.withDiplomatWrite(wasm, (write) => { - return wasm.ICU4XCaseMapper_fold_turkic(this.underlying, buf_arg_s.ptr, buf_arg_s.size, write); - }); - buf_arg_s.free(); - return diplomat_out; - } - - add_case_closure_to(arg_c, arg_builder) { - wasm.ICU4XCaseMapper_add_case_closure_to(this.underlying, diplomatRuntime.extractCodePoint(arg_c, 'arg_c'), arg_builder.underlying); - } - - simple_lowercase(arg_ch) { - return wasm.ICU4XCaseMapper_simple_lowercase(this.underlying, diplomatRuntime.extractCodePoint(arg_ch, 'arg_ch')); - } - - simple_uppercase(arg_ch) { - return wasm.ICU4XCaseMapper_simple_uppercase(this.underlying, diplomatRuntime.extractCodePoint(arg_ch, 'arg_ch')); - } - - simple_titlecase(arg_ch) { - return wasm.ICU4XCaseMapper_simple_titlecase(this.underlying, diplomatRuntime.extractCodePoint(arg_ch, 'arg_ch')); - } - - simple_fold(arg_ch) { - return wasm.ICU4XCaseMapper_simple_fold(this.underlying, diplomatRuntime.extractCodePoint(arg_ch, 'arg_ch')); - } - - simple_fold_turkic(arg_ch) { - return wasm.ICU4XCaseMapper_simple_fold_turkic(this.underlying, diplomatRuntime.extractCodePoint(arg_ch, 'arg_ch')); - } -} + + simpleTitlecase(ch) { + const result = wasm.ICU4XCaseMapper_simple_titlecase(this.ffiValue, diplomatRuntime.extractCodePoint(ch, 'ch')); + + try { + + return result; + } finally { + + } + } + + simpleFold(ch) { + const result = wasm.ICU4XCaseMapper_simple_fold(this.ffiValue, diplomatRuntime.extractCodePoint(ch, 'ch')); + + try { + + return result; + } finally { + + } + } + + simpleFoldTurkic(ch) { + const result = wasm.ICU4XCaseMapper_simple_fold_turkic(this.ffiValue, diplomatRuntime.extractCodePoint(ch, 'ch')); + + try { + + return result; + } finally { + + } + } + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/CodePointMapData16.d.ts b/ffi/capi/bindings/js/CodePointMapData16.d.ts index db6a359e9a9..34cbf11c53c 100644 --- a/ffi/capi/bindings/js/CodePointMapData16.d.ts +++ b/ffi/capi/bindings/js/CodePointMapData16.d.ts @@ -1,66 +1,36 @@ -import { u16, u32, char } from "./diplomat-runtime" -import { FFIError } from "./diplomat-runtime" -import { CodePointRangeIterator } from "./CodePointRangeIterator"; -import { CodePointSetData } from "./CodePointSetData"; -import { DataError } from "./DataError"; -import { DataProvider } from "./DataProvider"; - -/** - - * An ICU4X Unicode Map Property object, capable of querying whether a code point (key) to obtain the Unicode property value, for a specific Unicode property. - - * For properties whose values fit into 16 bits. - - * See the {@link https://docs.rs/icu/latest/icu/properties/index.html Rust documentation for `properties`} for more information. - - * See the {@link https://docs.rs/icu/latest/icu/properties/maps/struct.CodePointMapData.html Rust documentation for `CodePointMapData`} for more information. - - * See the {@link https://docs.rs/icu/latest/icu/properties/maps/struct.CodePointMapDataBorrowed.html Rust documentation for `CodePointMapDataBorrowed`} for more information. - */ +// generated by diplomat-tool +import type { CodePointRangeIterator } from "./CodePointRangeIterator" +import type { CodePointSetData } from "./CodePointSetData" +import type { DataProvider } from "./DataProvider" +import type { pointer, char } from "./diplomat-runtime.d.ts"; + + +/** An ICU4X Unicode Map Property object, capable of querying whether a code point (key) to obtain the Unicode property value, for a specific Unicode property. +* +*For properties whose values fit into 16 bits. +* +*See the [Rust documentation for `properties`](https://docs.rs/icu/latest/icu/properties/index.html) for more information. +* +*See the [Rust documentation for `CodePointMapData`](https://docs.rs/icu/latest/icu/properties/maps/struct.CodePointMapData.html) for more information. +* +*See the [Rust documentation for `CodePointMapDataBorrowed`](https://docs.rs/icu/latest/icu/properties/maps/struct.CodePointMapDataBorrowed.html) for more information. +*/ export class CodePointMapData16 { + - /** - - * Gets the value for a code point. - - * See the {@link https://docs.rs/icu/latest/icu/properties/maps/struct.CodePointMapDataBorrowed.html#method.get Rust documentation for `get`} for more information. - */ - get(cp: char): u16; - - /** - - * Gets the value for a code point (specified as a 32 bit integer, in UTF-32) - */ - get32(cp: u32): u16; - - /** - - * Produces an iterator over ranges of code points that map to `value` - - * See the {@link https://docs.rs/icu/latest/icu/properties/maps/struct.CodePointMapDataBorrowed.html#method.iter_ranges_for_value Rust documentation for `iter_ranges_for_value`} for more information. - */ - iter_ranges_for_value(value: u16): CodePointRangeIterator; + get ffiValue(): pointer; - /** - * Produces an iterator over ranges of code points that do not map to `value` + get(cp: char): number; - * See the {@link https://docs.rs/icu/latest/icu/properties/maps/struct.CodePointMapDataBorrowed.html#method.iter_ranges_for_value_complemented Rust documentation for `iter_ranges_for_value_complemented`} for more information. - */ - iter_ranges_for_value_complemented(value: u16): CodePointRangeIterator; + iterRangesForValue(value: number): CodePointRangeIterator; - /** + iterRangesForValueComplemented(value: number): CodePointRangeIterator; - * Gets a {@link CodePointSetData `CodePointSetData`} representing all entries in this map that map to the given value + getSetForValue(value: number): CodePointSetData; - * See the {@link https://docs.rs/icu/latest/icu/properties/maps/struct.CodePointMapDataBorrowed.html#method.get_set_for_value Rust documentation for `get_set_for_value`} for more information. - */ - get_set_for_value(value: u16): CodePointSetData; + static loadScript(provider: DataProvider): CodePointMapData16; - /** + - * See the {@link https://docs.rs/icu/latest/icu/properties/maps/fn.script.html Rust documentation for `script`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_script(provider: DataProvider): CodePointMapData16 | never; -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/CodePointMapData16.mjs b/ffi/capi/bindings/js/CodePointMapData16.mjs index a1c019e59b6..3f83b114bf9 100644 --- a/ffi/capi/bindings/js/CodePointMapData16.mjs +++ b/ffi/capi/bindings/js/CodePointMapData16.mjs @@ -1,57 +1,117 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" +// generated by diplomat-tool import { CodePointRangeIterator } from "./CodePointRangeIterator.mjs" import { CodePointSetData } from "./CodePointSetData.mjs" -import { DataError_js_to_rust, DataError_rust_to_js } from "./DataError.mjs" +import { DataError } from "./DataError.mjs" +import { DataProvider } from "./DataProvider.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -const CodePointMapData16_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XCodePointMapData16_destroy(underlying); -}); +/** An ICU4X Unicode Map Property object, capable of querying whether a code point (key) to obtain the Unicode property value, for a specific Unicode property. +* +*For properties whose values fit into 16 bits. +* +*See the [Rust documentation for `properties`](https://docs.rs/icu/latest/icu/properties/index.html) for more information. +* +*See the [Rust documentation for `CodePointMapData`](https://docs.rs/icu/latest/icu/properties/maps/struct.CodePointMapData.html) for more information. +* +*See the [Rust documentation for `CodePointMapDataBorrowed`](https://docs.rs/icu/latest/icu/properties/maps/struct.CodePointMapDataBorrowed.html) for more information. +*/ + +const CodePointMapData16_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XCodePointMapData16_destroy(ptr); +}); export class CodePointMapData16 { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - CodePointMapData16_box_destroy_registry.register(this, underlying); + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + + constructor(ptr, selfEdge) { + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + CodePointMapData16_box_destroy_registry.register(this, this.#ptr); + } + + get ffiValue() { + return this.#ptr; } - } - - get(arg_cp) { - return wasm.ICU4XCodePointMapData16_get(this.underlying, diplomatRuntime.extractCodePoint(arg_cp, 'arg_cp')); - } - - get32(arg_cp) { - return wasm.ICU4XCodePointMapData16_get32(this.underlying, arg_cp); - } - - iter_ranges_for_value(arg_value) { - return new CodePointRangeIterator(wasm.ICU4XCodePointMapData16_iter_ranges_for_value(this.underlying, arg_value), true, [this]); - } - - iter_ranges_for_value_complemented(arg_value) { - return new CodePointRangeIterator(wasm.ICU4XCodePointMapData16_iter_ranges_for_value_complemented(this.underlying, arg_value), true, [this]); - } - - get_set_for_value(arg_value) { - return new CodePointSetData(wasm.ICU4XCodePointMapData16_get_set_for_value(this.underlying, arg_value), true, []); - } - - static load_script(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointMapData16_load_script(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointMapData16(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } -} + + + get(cp) { + const result = wasm.ICU4XCodePointMapData16_get(this.ffiValue, diplomatRuntime.extractCodePoint(cp, 'cp')); + + try { + + return result; + } finally { + + } + } + + iterRangesForValue(value) { + + // This lifetime edge depends on lifetimes 'a + let aEdges = [this]; + const result = wasm.ICU4XCodePointMapData16_iter_ranges_for_value(this.ffiValue, value); + + try { + + return new CodePointRangeIterator(result, [], aEdges); + } finally { + + } + } + + iterRangesForValueComplemented(value) { + + // This lifetime edge depends on lifetimes 'a + let aEdges = [this]; + const result = wasm.ICU4XCodePointMapData16_iter_ranges_for_value_complemented(this.ffiValue, value); + + try { + + return new CodePointRangeIterator(result, [], aEdges); + } finally { + + } + } + + getSetForValue(value) { + const result = wasm.ICU4XCodePointMapData16_get_set_for_value(this.ffiValue, value); + + try { + + return new CodePointSetData(result, []); + } finally { + + } + } + + static loadScript(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointMapData16_load_script(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointMapData16(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/CodePointMapData8.d.ts b/ffi/capi/bindings/js/CodePointMapData8.d.ts index 1796daf8635..e77641c990e 100644 --- a/ffi/capi/bindings/js/CodePointMapData8.d.ts +++ b/ffi/capi/bindings/js/CodePointMapData8.d.ts @@ -1,151 +1,58 @@ -import { u8, u32, char } from "./diplomat-runtime" -import { FFIError } from "./diplomat-runtime" -import { CodePointRangeIterator } from "./CodePointRangeIterator"; -import { CodePointSetData } from "./CodePointSetData"; -import { DataError } from "./DataError"; -import { DataProvider } from "./DataProvider"; - -/** - - * An ICU4X Unicode Map Property object, capable of querying whether a code point (key) to obtain the Unicode property value, for a specific Unicode property. - - * For properties whose values fit into 8 bits. - - * See the {@link https://docs.rs/icu/latest/icu/properties/index.html Rust documentation for `properties`} for more information. - - * See the {@link https://docs.rs/icu/latest/icu/properties/maps/struct.CodePointMapData.html Rust documentation for `CodePointMapData`} for more information. - - * See the {@link https://docs.rs/icu/latest/icu/properties/maps/struct.CodePointMapDataBorrowed.html Rust documentation for `CodePointMapDataBorrowed`} for more information. - */ +// generated by diplomat-tool +import type { CodePointRangeIterator } from "./CodePointRangeIterator" +import type { CodePointSetData } from "./CodePointSetData" +import type { DataProvider } from "./DataProvider" +import type { pointer, char } from "./diplomat-runtime.d.ts"; + + +/** An ICU4X Unicode Map Property object, capable of querying whether a code point (key) to obtain the Unicode property value, for a specific Unicode property. +* +*For properties whose values fit into 8 bits. +* +*See the [Rust documentation for `properties`](https://docs.rs/icu/latest/icu/properties/index.html) for more information. +* +*See the [Rust documentation for `CodePointMapData`](https://docs.rs/icu/latest/icu/properties/maps/struct.CodePointMapData.html) for more information. +* +*See the [Rust documentation for `CodePointMapDataBorrowed`](https://docs.rs/icu/latest/icu/properties/maps/struct.CodePointMapDataBorrowed.html) for more information. +*/ export class CodePointMapData8 { + - /** - - * Gets the value for a code point. - - * See the {@link https://docs.rs/icu/latest/icu/properties/maps/struct.CodePointMapDataBorrowed.html#method.get Rust documentation for `get`} for more information. - */ - get(cp: char): u8; - - /** - - * Gets the value for a code point (specified as a 32 bit integer, in UTF-32) - */ - get32(cp: u32): u8; - - /** - - * Converts a general category to its corresponding mask value - - * Nonexistent general categories will map to the empty mask - - * See the {@link https://docs.rs/icu/latest/icu/properties/struct.GeneralCategoryGroup.html Rust documentation for `GeneralCategoryGroup`} for more information. - */ - static general_category_to_mask(gc: u8): u32; - - /** - - * Produces an iterator over ranges of code points that map to `value` - - * See the {@link https://docs.rs/icu/latest/icu/properties/maps/struct.CodePointMapDataBorrowed.html#method.iter_ranges_for_value Rust documentation for `iter_ranges_for_value`} for more information. - */ - iter_ranges_for_value(value: u8): CodePointRangeIterator; - - /** - - * Produces an iterator over ranges of code points that do not map to `value` - - * See the {@link https://docs.rs/icu/latest/icu/properties/maps/struct.CodePointMapDataBorrowed.html#method.iter_ranges_for_value_complemented Rust documentation for `iter_ranges_for_value_complemented`} for more information. - */ - iter_ranges_for_value_complemented(value: u8): CodePointRangeIterator; - - /** - - * Given a mask value (the nth bit marks property value = n), produce an iterator over ranges of code points whose property values are contained in the mask. - - * The main mask property supported is that for General_Category, which can be obtained via `general_category_to_mask()` or by using `GeneralCategoryNameToMaskMapper` - - * Should only be used on maps for properties with values less than 32 (like Generak_Category), other maps will have unpredictable results - - * See the {@link https://docs.rs/icu/latest/icu/properties/maps/struct.CodePointMapDataBorrowed.html#method.iter_ranges_for_group Rust documentation for `iter_ranges_for_group`} for more information. - */ - iter_ranges_for_mask(mask: u32): CodePointRangeIterator; - - /** - - * Gets a {@link CodePointSetData `CodePointSetData`} representing all entries in this map that map to the given value - - * See the {@link https://docs.rs/icu/latest/icu/properties/maps/struct.CodePointMapDataBorrowed.html#method.get_set_for_value Rust documentation for `get_set_for_value`} for more information. - */ - get_set_for_value(value: u8): CodePointSetData; - - /** + get ffiValue(): pointer; - * See the {@link https://docs.rs/icu/latest/icu/properties/maps/fn.general_category.html Rust documentation for `general_category`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_general_category(provider: DataProvider): CodePointMapData8 | never; - /** + get(cp: char): number; - * See the {@link https://docs.rs/icu/latest/icu/properties/maps/fn.bidi_class.html Rust documentation for `bidi_class`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_bidi_class(provider: DataProvider): CodePointMapData8 | never; + static generalCategoryToMask(gc: number): number; - /** + iterRangesForValue(value: number): CodePointRangeIterator; - * See the {@link https://docs.rs/icu/latest/icu/properties/maps/fn.east_asian_width.html Rust documentation for `east_asian_width`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_east_asian_width(provider: DataProvider): CodePointMapData8 | never; + iterRangesForValueComplemented(value: number): CodePointRangeIterator; - /** + iterRangesForMask(mask: number): CodePointRangeIterator; - * See the {@link https://docs.rs/icu/latest/icu/properties/maps/fn.hangul_syllable_type.html Rust documentation for `hangul_syllable_type`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_hangul_syllable_type(provider: DataProvider): CodePointMapData8 | never; + getSetForValue(value: number): CodePointSetData; - /** + static loadGeneralCategory(provider: DataProvider): CodePointMapData8; - * See the {@link https://docs.rs/icu/latest/icu/properties/maps/fn.indic_syllabic_category.html Rust documentation for `indic_syllabic_category`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_indic_syllabic_category(provider: DataProvider): CodePointMapData8 | never; + static loadBidiClass(provider: DataProvider): CodePointMapData8; - /** + static loadEastAsianWidth(provider: DataProvider): CodePointMapData8; - * See the {@link https://docs.rs/icu/latest/icu/properties/maps/fn.line_break.html Rust documentation for `line_break`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_line_break(provider: DataProvider): CodePointMapData8 | never; + static loadHangulSyllableType(provider: DataProvider): CodePointMapData8; - /** + static loadIndicSyllabicCategory(provider: DataProvider): CodePointMapData8; - * See the {@link https://docs.rs/icu/latest/icu/properties/maps/fn.grapheme_cluster_break.html Rust documentation for `grapheme_cluster_break`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static try_grapheme_cluster_break(provider: DataProvider): CodePointMapData8 | never; + static loadLineBreak(provider: DataProvider): CodePointMapData8; - /** + static tryGraphemeClusterBreak(provider: DataProvider): CodePointMapData8; - * See the {@link https://docs.rs/icu/latest/icu/properties/maps/fn.word_break.html Rust documentation for `word_break`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_word_break(provider: DataProvider): CodePointMapData8 | never; + static loadWordBreak(provider: DataProvider): CodePointMapData8; - /** + static loadSentenceBreak(provider: DataProvider): CodePointMapData8; - * See the {@link https://docs.rs/icu/latest/icu/properties/maps/fn.sentence_break.html Rust documentation for `sentence_break`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_sentence_break(provider: DataProvider): CodePointMapData8 | never; + static loadJoiningType(provider: DataProvider): CodePointMapData8; - /** + - * See the {@link https://docs.rs/icu/latest/icu/properties/maps/fn.joining_type.html Rust documentation for `joining_type`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_joining_type(provider: DataProvider): CodePointMapData8 | never; -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/CodePointMapData8.mjs b/ffi/capi/bindings/js/CodePointMapData8.mjs index c87dc0e4eb7..5dafc1ca34a 100644 --- a/ffi/capi/bindings/js/CodePointMapData8.mjs +++ b/ffi/capi/bindings/js/CodePointMapData8.mjs @@ -1,218 +1,313 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" +// generated by diplomat-tool import { CodePointRangeIterator } from "./CodePointRangeIterator.mjs" import { CodePointSetData } from "./CodePointSetData.mjs" -import { DataError_js_to_rust, DataError_rust_to_js } from "./DataError.mjs" +import { DataError } from "./DataError.mjs" +import { DataProvider } from "./DataProvider.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -const CodePointMapData8_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XCodePointMapData8_destroy(underlying); -}); +/** An ICU4X Unicode Map Property object, capable of querying whether a code point (key) to obtain the Unicode property value, for a specific Unicode property. +* +*For properties whose values fit into 8 bits. +* +*See the [Rust documentation for `properties`](https://docs.rs/icu/latest/icu/properties/index.html) for more information. +* +*See the [Rust documentation for `CodePointMapData`](https://docs.rs/icu/latest/icu/properties/maps/struct.CodePointMapData.html) for more information. +* +*See the [Rust documentation for `CodePointMapDataBorrowed`](https://docs.rs/icu/latest/icu/properties/maps/struct.CodePointMapDataBorrowed.html) for more information. +*/ + +const CodePointMapData8_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XCodePointMapData8_destroy(ptr); +}); export class CodePointMapData8 { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - CodePointMapData8_box_destroy_registry.register(this, underlying); - } - } - - get(arg_cp) { - return wasm.ICU4XCodePointMapData8_get(this.underlying, diplomatRuntime.extractCodePoint(arg_cp, 'arg_cp')); - } - - get32(arg_cp) { - return wasm.ICU4XCodePointMapData8_get32(this.underlying, arg_cp); - } - - static general_category_to_mask(arg_gc) { - return wasm.ICU4XCodePointMapData8_general_category_to_mask(arg_gc); - } - - iter_ranges_for_value(arg_value) { - return new CodePointRangeIterator(wasm.ICU4XCodePointMapData8_iter_ranges_for_value(this.underlying, arg_value), true, [this]); - } - - iter_ranges_for_value_complemented(arg_value) { - return new CodePointRangeIterator(wasm.ICU4XCodePointMapData8_iter_ranges_for_value_complemented(this.underlying, arg_value), true, [this]); - } - - iter_ranges_for_mask(arg_mask) { - return new CodePointRangeIterator(wasm.ICU4XCodePointMapData8_iter_ranges_for_mask(this.underlying, arg_mask), true, [this]); - } - - get_set_for_value(arg_value) { - return new CodePointSetData(wasm.ICU4XCodePointMapData8_get_set_for_value(this.underlying, arg_value), true, []); - } - - static load_general_category(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointMapData8_load_general_category(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointMapData8(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_bidi_class(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointMapData8_load_bidi_class(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointMapData8(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_east_asian_width(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointMapData8_load_east_asian_width(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointMapData8(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_hangul_syllable_type(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointMapData8_load_hangul_syllable_type(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointMapData8(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_indic_syllabic_category(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointMapData8_load_indic_syllabic_category(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointMapData8(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_line_break(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointMapData8_load_line_break(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointMapData8(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static try_grapheme_cluster_break(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointMapData8_try_grapheme_cluster_break(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointMapData8(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_word_break(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointMapData8_load_word_break(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointMapData8(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_sentence_break(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointMapData8_load_sentence_break(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointMapData8(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_joining_type(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointMapData8_load_joining_type(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointMapData8(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } -} + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + + constructor(ptr, selfEdge) { + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + CodePointMapData8_box_destroy_registry.register(this, this.#ptr); + } + + get ffiValue() { + return this.#ptr; + } + + + get(cp) { + const result = wasm.ICU4XCodePointMapData8_get(this.ffiValue, diplomatRuntime.extractCodePoint(cp, 'cp')); + + try { + + return result; + } finally { + + } + } + + static generalCategoryToMask(gc) { + const result = wasm.ICU4XCodePointMapData8_general_category_to_mask(gc); + + try { + + return result; + } finally { + + } + } + + iterRangesForValue(value) { + + // This lifetime edge depends on lifetimes 'a + let aEdges = [this]; + const result = wasm.ICU4XCodePointMapData8_iter_ranges_for_value(this.ffiValue, value); + + try { + + return new CodePointRangeIterator(result, [], aEdges); + } finally { + + } + } + + iterRangesForValueComplemented(value) { + + // This lifetime edge depends on lifetimes 'a + let aEdges = [this]; + const result = wasm.ICU4XCodePointMapData8_iter_ranges_for_value_complemented(this.ffiValue, value); + + try { + + return new CodePointRangeIterator(result, [], aEdges); + } finally { + + } + } + + iterRangesForMask(mask) { + + // This lifetime edge depends on lifetimes 'a + let aEdges = [this]; + const result = wasm.ICU4XCodePointMapData8_iter_ranges_for_mask(this.ffiValue, mask); + + try { + + return new CodePointRangeIterator(result, [], aEdges); + } finally { + + } + } + + getSetForValue(value) { + const result = wasm.ICU4XCodePointMapData8_get_set_for_value(this.ffiValue, value); + + try { + + return new CodePointSetData(result, []); + } finally { + + } + } + + static loadGeneralCategory(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointMapData8_load_general_category(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointMapData8(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadBidiClass(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointMapData8_load_bidi_class(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointMapData8(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadEastAsianWidth(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointMapData8_load_east_asian_width(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointMapData8(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadHangulSyllableType(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointMapData8_load_hangul_syllable_type(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointMapData8(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadIndicSyllabicCategory(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointMapData8_load_indic_syllabic_category(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointMapData8(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadLineBreak(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointMapData8_load_line_break(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointMapData8(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static tryGraphemeClusterBreak(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointMapData8_try_grapheme_cluster_break(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointMapData8(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadWordBreak(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointMapData8_load_word_break(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointMapData8(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadSentenceBreak(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointMapData8_load_sentence_break(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointMapData8(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadJoiningType(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointMapData8_load_joining_type(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointMapData8(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/CodePointRangeIterator.d.ts b/ffi/capi/bindings/js/CodePointRangeIterator.d.ts index 1de5be8f289..992a8567cba 100644 --- a/ffi/capi/bindings/js/CodePointRangeIterator.d.ts +++ b/ffi/capi/bindings/js/CodePointRangeIterator.d.ts @@ -1,16 +1,19 @@ -import { CodePointRangeIteratorResult } from "./CodePointRangeIteratorResult"; +// generated by diplomat-tool +import type { CodePointRangeIteratorResult } from "./CodePointRangeIteratorResult" +import type { pointer, char } from "./diplomat-runtime.d.ts"; -/** - * An iterator over code point ranges, produced by `CodePointSetData` or one of the `CodePointMapData` types - */ +/** An iterator over code point ranges, produced by `CodePointSetData` or +*one of the `CodePointMapData` types +*/ export class CodePointRangeIterator { + - /** + get ffiValue(): pointer; - * Advance the iterator by one and return the next range. - * If the iterator is out of items, `done` will be true - */ - next(): CodePointRangeIteratorResult; -} + next(): CodePointRangeIteratorResult; + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/CodePointRangeIterator.mjs b/ffi/capi/bindings/js/CodePointRangeIterator.mjs index 18c23a67e62..cdd7a607a88 100644 --- a/ffi/capi/bindings/js/CodePointRangeIterator.mjs +++ b/ffi/capi/bindings/js/CodePointRangeIterator.mjs @@ -1,28 +1,58 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" +// generated by diplomat-tool import { CodePointRangeIteratorResult } from "./CodePointRangeIteratorResult.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -const CodePointRangeIterator_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XCodePointRangeIterator_destroy(underlying); -}); +/** An iterator over code point ranges, produced by `CodePointSetData` or +*one of the `CodePointMapData` types +*/ + +const CodePointRangeIterator_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XCodePointRangeIterator_destroy(ptr); +}); export class CodePointRangeIterator { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - CodePointRangeIterator_box_destroy_registry.register(this, underlying); + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + #aEdge = []; + + + constructor(ptr, selfEdge, aEdge) { + + + this.#aEdge = aEdge; + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + CodePointRangeIterator_box_destroy_registry.register(this, this.#ptr); + } + + get ffiValue() { + return this.#ptr; } - } - - next() { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(9, 4); - wasm.ICU4XCodePointRangeIterator_next(diplomat_receive_buffer, this.underlying); - const out = new CodePointRangeIteratorResult(diplomat_receive_buffer); - wasm.diplomat_free(diplomat_receive_buffer, 9, 4); - return out; - })(); - } -} + + + next() { + + const diplomat_receive_buffer = wasm.diplomat_alloc(9, 4); + const result = wasm.ICU4XCodePointRangeIterator_next(diplomat_receive_buffer, this.ffiValue); + + try { + + return new CodePointRangeIteratorResult(diplomat_receive_buffer); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 9, 4); + + } + } + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/CodePointRangeIteratorResult.d.ts b/ffi/capi/bindings/js/CodePointRangeIteratorResult.d.ts index bcc72a65a61..2c2beaa7930 100644 --- a/ffi/capi/bindings/js/CodePointRangeIteratorResult.d.ts +++ b/ffi/capi/bindings/js/CodePointRangeIteratorResult.d.ts @@ -1,13 +1,23 @@ -import { u32 } from "./diplomat-runtime" +// generated by diplomat-tool +import type { pointer, char } from "./diplomat-runtime.d.ts"; -/** - * Result of a single iteration of {@link CodePointRangeIterator `CodePointRangeIterator`}. Logically can be considered to be an `Option>`, - - * `start` and `end` represent an inclusive range of code points start, end, and `done` will be true if the iterator has already finished. The last contentful iteration will NOT produce a range done=true, in other words `start` and `end` are useful values if and only if `done=false`. - */ +/** Result of a single iteration of [`CodePointRangeIterator`]. +*Logically can be considered to be an `Option>`, +* +*`start` and `end` represent an inclusive range of code points [start, end], +*and `done` will be true if the iterator has already finished. The last contentful +*iteration will NOT produce a range done=true, in other words `start` and `end` are useful +*values if and only if `done=false`. +*/ export class CodePointRangeIteratorResult { - start: u32; - end: u32; - done: boolean; -} + get start() : number; + + get end() : number; + + get done() : boolean; + + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/CodePointRangeIteratorResult.mjs b/ffi/capi/bindings/js/CodePointRangeIteratorResult.mjs index 29ff7b32d58..9ca2ed6bc22 100644 --- a/ffi/capi/bindings/js/CodePointRangeIteratorResult.mjs +++ b/ffi/capi/bindings/js/CodePointRangeIteratorResult.mjs @@ -1,10 +1,62 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" +// generated by diplomat-tool +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; + +/** Result of a single iteration of [`CodePointRangeIterator`]. +*Logically can be considered to be an `Option>`, +* +*`start` and `end` represent an inclusive range of code points [start, end], +*and `done` will be true if the iterator has already finished. The last contentful +*iteration will NOT produce a range done=true, in other words `start` and `end` are useful +*values if and only if `done=false`. +*/ export class CodePointRangeIteratorResult { - constructor(underlying) { - this.start = (new Uint32Array(wasm.memory.buffer, underlying, 1))[0]; - this.end = (new Uint32Array(wasm.memory.buffer, underlying + 4, 1))[0]; - this.done = (new Uint8Array(wasm.memory.buffer, underlying + 8, 1))[0] == 1; - } -} + #start; + get start() { + return this.#start; + } + + #end; + get end() { + return this.#end; + } + + #done; + get done() { + return this.#done; + } + + + // Return this struct in FFI function friendly format. + // Returns an array that can be expanded with spread syntax (...) + + _intoFFI( + slice_cleanup_callbacks, + appendArrayMap + ) { + return [this.#start, this.#end, this.#done] + } + + // 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. + _fromFFI(ptr) { + const startDeref = (new Uint32Array(wasm.memory.buffer, ptr, 1))[0]; + this.#start = startDeref; + const endDeref = (new Uint32Array(wasm.memory.buffer, ptr + 4, 1))[0]; + this.#end = endDeref; + const doneDeref = (new Uint8Array(wasm.memory.buffer, ptr + 8, 1))[0] == 1; + this.#done = doneDeref; + + return this; + } + // This is an out struct. You need to call other methods to be able to get this struct. + constructor(ptr) { + this._fromFFI(ptr); + } + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/CodePointSetBuilder.d.ts b/ffi/capi/bindings/js/CodePointSetBuilder.d.ts index 46fbdcafb5c..76981eb6012 100644 --- a/ffi/capi/bindings/js/CodePointSetBuilder.d.ts +++ b/ffi/capi/bindings/js/CodePointSetBuilder.d.ts @@ -1,147 +1,48 @@ -import { char } from "./diplomat-runtime" -import { CodePointSetData } from "./CodePointSetData"; +// generated by diplomat-tool +import type { CodePointSetData } from "./CodePointSetData" +import type { pointer, char } from "./diplomat-runtime.d.ts"; -/** - * See the {@link https://docs.rs/icu/latest/icu/collections/codepointinvlist/struct.CodePointInversionListBuilder.html Rust documentation for `CodePointInversionListBuilder`} for more information. - */ +/** See the [Rust documentation for `CodePointInversionListBuilder`](https://docs.rs/icu/latest/icu/collections/codepointinvlist/struct.CodePointInversionListBuilder.html) for more information. +*/ export class CodePointSetBuilder { + - /** + get ffiValue(): pointer; - * Make a new set builder containing nothing - * See the {@link https://docs.rs/icu/latest/icu/collections/codepointinvlist/struct.CodePointInversionListBuilder.html#method.new Rust documentation for `new`} for more information. - */ - static create(): CodePointSetBuilder; + static create(): CodePointSetBuilder; - /** + build(): CodePointSetData; - * Build this into a set + complement(): void; - * This object is repopulated with an empty builder + get isEmpty(): boolean; - * See the {@link https://docs.rs/icu/latest/icu/collections/codepointinvlist/struct.CodePointInversionListBuilder.html#method.build Rust documentation for `build`} for more information. - */ - build(): CodePointSetData; + addChar(ch: char): void; - /** + addInclusiveRange(start: char, end: char): void; - * Complements this set + addSet(data: CodePointSetData): void; - * (Elements in this set are removed and vice versa) + removeChar(ch: char): void; - * See the {@link https://docs.rs/icu/latest/icu/collections/codepointinvlist/struct.CodePointInversionListBuilder.html#method.complement Rust documentation for `complement`} for more information. - */ - complement(): void; + removeInclusiveRange(start: char, end: char): void; - /** + removeSet(data: CodePointSetData): void; - * Returns whether this set is empty + retainChar(ch: char): void; - * See the {@link https://docs.rs/icu/latest/icu/collections/codepointinvlist/struct.CodePointInversionListBuilder.html#method.is_empty Rust documentation for `is_empty`} for more information. - */ - is_empty(): boolean; + retainInclusiveRange(start: char, end: char): void; - /** + retainSet(data: CodePointSetData): void; - * Add a single character to the set + complementChar(ch: char): void; - * See the {@link https://docs.rs/icu/latest/icu/collections/codepointinvlist/struct.CodePointInversionListBuilder.html#method.add_char Rust documentation for `add_char`} for more information. - */ - add_char(ch: char): void; + complementInclusiveRange(start: char, end: char): void; - /** + complementSet(data: CodePointSetData): void; - * Add an inclusive range of characters to the set + - * See the {@link https://docs.rs/icu/latest/icu/collections/codepointinvlist/struct.CodePointInversionListBuilder.html#method.add_range Rust documentation for `add_range`} for more information. - */ - add_inclusive_range(start: char, end: char): void; - - /** - - * Add all elements that belong to the provided set to the set - - * See the {@link https://docs.rs/icu/latest/icu/collections/codepointinvlist/struct.CodePointInversionListBuilder.html#method.add_set Rust documentation for `add_set`} for more information. - */ - add_set(data: CodePointSetData): void; - - /** - - * Remove a single character to the set - - * See the {@link https://docs.rs/icu/latest/icu/collections/codepointinvlist/struct.CodePointInversionListBuilder.html#method.remove_char Rust documentation for `remove_char`} for more information. - */ - remove_char(ch: char): void; - - /** - - * Remove an inclusive range of characters from the set - - * See the {@link https://docs.rs/icu/latest/icu/collections/codepointinvlist/struct.CodePointInversionListBuilder.html#method.remove_range Rust documentation for `remove_range`} for more information. - */ - remove_inclusive_range(start: char, end: char): void; - - /** - - * Remove all elements that belong to the provided set from the set - - * See the {@link https://docs.rs/icu/latest/icu/collections/codepointinvlist/struct.CodePointInversionListBuilder.html#method.remove_set Rust documentation for `remove_set`} for more information. - */ - remove_set(data: CodePointSetData): void; - - /** - - * Removes all elements from the set except a single character - - * See the {@link https://docs.rs/icu/latest/icu/collections/codepointinvlist/struct.CodePointInversionListBuilder.html#method.retain_char Rust documentation for `retain_char`} for more information. - */ - retain_char(ch: char): void; - - /** - - * Removes all elements from the set except an inclusive range of characters f - - * See the {@link https://docs.rs/icu/latest/icu/collections/codepointinvlist/struct.CodePointInversionListBuilder.html#method.retain_range Rust documentation for `retain_range`} for more information. - */ - retain_inclusive_range(start: char, end: char): void; - - /** - - * Removes all elements from the set except all elements in the provided set - - * See the {@link https://docs.rs/icu/latest/icu/collections/codepointinvlist/struct.CodePointInversionListBuilder.html#method.retain_set Rust documentation for `retain_set`} for more information. - */ - retain_set(data: CodePointSetData): void; - - /** - - * Complement a single character to the set - - * (Characters which are in this set are removed and vice versa) - - * See the {@link https://docs.rs/icu/latest/icu/collections/codepointinvlist/struct.CodePointInversionListBuilder.html#method.complement_char Rust documentation for `complement_char`} for more information. - */ - complement_char(ch: char): void; - - /** - - * Complement an inclusive range of characters from the set - - * (Characters which are in this set are removed and vice versa) - - * See the {@link https://docs.rs/icu/latest/icu/collections/codepointinvlist/struct.CodePointInversionListBuilder.html#method.complement_range Rust documentation for `complement_range`} for more information. - */ - complement_inclusive_range(start: char, end: char): void; - - /** - - * Complement all elements that belong to the provided set from the set - - * (Characters which are in this set are removed and vice versa) - - * See the {@link https://docs.rs/icu/latest/icu/collections/codepointinvlist/struct.CodePointInversionListBuilder.html#method.complement_set Rust documentation for `complement_set`} for more information. - */ - complement_set(data: CodePointSetData): void; -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/CodePointSetBuilder.mjs b/ffi/capi/bindings/js/CodePointSetBuilder.mjs index b130bdd2149..d02280658a5 100644 --- a/ffi/capi/bindings/js/CodePointSetBuilder.mjs +++ b/ffi/capi/bindings/js/CodePointSetBuilder.mjs @@ -1,82 +1,200 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" +// generated by diplomat-tool import { CodePointSetData } from "./CodePointSetData.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -const CodePointSetBuilder_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XCodePointSetBuilder_destroy(underlying); -}); +/** See the [Rust documentation for `CodePointInversionListBuilder`](https://docs.rs/icu/latest/icu/collections/codepointinvlist/struct.CodePointInversionListBuilder.html) for more information. +*/ + +const CodePointSetBuilder_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XCodePointSetBuilder_destroy(ptr); +}); export class CodePointSetBuilder { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - CodePointSetBuilder_box_destroy_registry.register(this, underlying); - } - } - - static create() { - return new CodePointSetBuilder(wasm.ICU4XCodePointSetBuilder_create(), true, []); - } - - build() { - return new CodePointSetData(wasm.ICU4XCodePointSetBuilder_build(this.underlying), true, []); - } - - complement() { - wasm.ICU4XCodePointSetBuilder_complement(this.underlying); - } - - is_empty() { - return wasm.ICU4XCodePointSetBuilder_is_empty(this.underlying); - } - - add_char(arg_ch) { - wasm.ICU4XCodePointSetBuilder_add_char(this.underlying, diplomatRuntime.extractCodePoint(arg_ch, 'arg_ch')); - } - - add_inclusive_range(arg_start, arg_end) { - wasm.ICU4XCodePointSetBuilder_add_inclusive_range(this.underlying, diplomatRuntime.extractCodePoint(arg_start, 'arg_start'), diplomatRuntime.extractCodePoint(arg_end, 'arg_end')); - } - - add_set(arg_data) { - wasm.ICU4XCodePointSetBuilder_add_set(this.underlying, arg_data.underlying); - } - - remove_char(arg_ch) { - wasm.ICU4XCodePointSetBuilder_remove_char(this.underlying, diplomatRuntime.extractCodePoint(arg_ch, 'arg_ch')); - } - - remove_inclusive_range(arg_start, arg_end) { - wasm.ICU4XCodePointSetBuilder_remove_inclusive_range(this.underlying, diplomatRuntime.extractCodePoint(arg_start, 'arg_start'), diplomatRuntime.extractCodePoint(arg_end, 'arg_end')); - } - - remove_set(arg_data) { - wasm.ICU4XCodePointSetBuilder_remove_set(this.underlying, arg_data.underlying); - } - - retain_char(arg_ch) { - wasm.ICU4XCodePointSetBuilder_retain_char(this.underlying, diplomatRuntime.extractCodePoint(arg_ch, 'arg_ch')); - } - - retain_inclusive_range(arg_start, arg_end) { - wasm.ICU4XCodePointSetBuilder_retain_inclusive_range(this.underlying, diplomatRuntime.extractCodePoint(arg_start, 'arg_start'), diplomatRuntime.extractCodePoint(arg_end, 'arg_end')); - } - - retain_set(arg_data) { - wasm.ICU4XCodePointSetBuilder_retain_set(this.underlying, arg_data.underlying); - } - - complement_char(arg_ch) { - wasm.ICU4XCodePointSetBuilder_complement_char(this.underlying, diplomatRuntime.extractCodePoint(arg_ch, 'arg_ch')); - } - - complement_inclusive_range(arg_start, arg_end) { - wasm.ICU4XCodePointSetBuilder_complement_inclusive_range(this.underlying, diplomatRuntime.extractCodePoint(arg_start, 'arg_start'), diplomatRuntime.extractCodePoint(arg_end, 'arg_end')); - } - - complement_set(arg_data) { - wasm.ICU4XCodePointSetBuilder_complement_set(this.underlying, arg_data.underlying); - } -} + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + + constructor(ptr, selfEdge) { + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + CodePointSetBuilder_box_destroy_registry.register(this, this.#ptr); + } + + get ffiValue() { + return this.#ptr; + } + + + static create() { + const result = wasm.ICU4XCodePointSetBuilder_create(); + + try { + + return new CodePointSetBuilder(result, []); + } finally { + + } + } + + build() { + const result = wasm.ICU4XCodePointSetBuilder_build(this.ffiValue); + + try { + + return new CodePointSetData(result, []); + } finally { + + } + } + + complement() { + wasm.ICU4XCodePointSetBuilder_complement(this.ffiValue); + + try { + + } finally { + + } + } + + get isEmpty() { + const result = wasm.ICU4XCodePointSetBuilder_is_empty(this.ffiValue); + + try { + + return result; + } finally { + + } + } + + addChar(ch) { + wasm.ICU4XCodePointSetBuilder_add_char(this.ffiValue, diplomatRuntime.extractCodePoint(ch, 'ch')); + + try { + + } finally { + + } + } + + addInclusiveRange(start, end) { + wasm.ICU4XCodePointSetBuilder_add_inclusive_range(this.ffiValue, diplomatRuntime.extractCodePoint(start, 'start'), diplomatRuntime.extractCodePoint(end, 'end')); + + try { + + } finally { + + } + } + + addSet(data) { + wasm.ICU4XCodePointSetBuilder_add_set(this.ffiValue, data.ffiValue); + + try { + + } finally { + + } + } + + removeChar(ch) { + wasm.ICU4XCodePointSetBuilder_remove_char(this.ffiValue, diplomatRuntime.extractCodePoint(ch, 'ch')); + + try { + + } finally { + + } + } + + removeInclusiveRange(start, end) { + wasm.ICU4XCodePointSetBuilder_remove_inclusive_range(this.ffiValue, diplomatRuntime.extractCodePoint(start, 'start'), diplomatRuntime.extractCodePoint(end, 'end')); + + try { + + } finally { + + } + } + + removeSet(data) { + wasm.ICU4XCodePointSetBuilder_remove_set(this.ffiValue, data.ffiValue); + + try { + + } finally { + + } + } + + retainChar(ch) { + wasm.ICU4XCodePointSetBuilder_retain_char(this.ffiValue, diplomatRuntime.extractCodePoint(ch, 'ch')); + + try { + + } finally { + + } + } + + retainInclusiveRange(start, end) { + wasm.ICU4XCodePointSetBuilder_retain_inclusive_range(this.ffiValue, diplomatRuntime.extractCodePoint(start, 'start'), diplomatRuntime.extractCodePoint(end, 'end')); + + try { + + } finally { + + } + } + + retainSet(data) { + wasm.ICU4XCodePointSetBuilder_retain_set(this.ffiValue, data.ffiValue); + + try { + + } finally { + + } + } + + complementChar(ch) { + wasm.ICU4XCodePointSetBuilder_complement_char(this.ffiValue, diplomatRuntime.extractCodePoint(ch, 'ch')); + + try { + + } finally { + + } + } + + complementInclusiveRange(start, end) { + wasm.ICU4XCodePointSetBuilder_complement_inclusive_range(this.ffiValue, diplomatRuntime.extractCodePoint(start, 'start'), diplomatRuntime.extractCodePoint(end, 'end')); + + try { + + } finally { + + } + } + + complementSet(data) { + wasm.ICU4XCodePointSetBuilder_complement_set(this.ffiValue, data.ffiValue); + + try { + + } finally { + + } + } + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/CodePointSetData.d.ts b/ffi/capi/bindings/js/CodePointSetData.d.ts index e202301c1e7..df6a09be35f 100644 --- a/ffi/capi/bindings/js/CodePointSetData.d.ts +++ b/ffi/capi/bindings/js/CodePointSetData.d.ts @@ -1,524 +1,163 @@ -import { u32, char } from "./diplomat-runtime" -import { FFIError } from "./diplomat-runtime" -import { CodePointRangeIterator } from "./CodePointRangeIterator"; -import { DataError } from "./DataError"; -import { DataProvider } from "./DataProvider"; -import { Error } from "./Error"; - -/** - - * An ICU4X Unicode Set Property object, capable of querying whether a code point is contained in a set based on a Unicode property. - - * See the {@link https://docs.rs/icu/latest/icu/properties/index.html Rust documentation for `properties`} for more information. - - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/struct.CodePointSetData.html Rust documentation for `CodePointSetData`} for more information. - - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/struct.CodePointSetDataBorrowed.html Rust documentation for `CodePointSetDataBorrowed`} for more information. - */ +// generated by diplomat-tool +import type { CodePointRangeIterator } from "./CodePointRangeIterator" +import type { DataProvider } from "./DataProvider" +import type { pointer, char } from "./diplomat-runtime.d.ts"; + + +/** An ICU4X Unicode Set Property object, capable of querying whether a code point is contained in a set based on a Unicode property. +* +*See the [Rust documentation for `properties`](https://docs.rs/icu/latest/icu/properties/index.html) for more information. +* +*See the [Rust documentation for `CodePointSetData`](https://docs.rs/icu/latest/icu/properties/sets/struct.CodePointSetData.html) for more information. +* +*See the [Rust documentation for `CodePointSetDataBorrowed`](https://docs.rs/icu/latest/icu/properties/sets/struct.CodePointSetDataBorrowed.html) for more information. +*/ export class CodePointSetData { + - /** - - * Checks whether the code point is in the set. - - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/struct.CodePointSetDataBorrowed.html#method.contains Rust documentation for `contains`} for more information. - */ - contains(cp: char): boolean; - - /** - - * Checks whether the code point (specified as a 32 bit integer, in UTF-32) is in the set. - */ - contains32(cp: u32): boolean; - - /** - - * Produces an iterator over ranges of code points contained in this set - - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/struct.CodePointSetDataBorrowed.html#method.iter_ranges Rust documentation for `iter_ranges`} for more information. - */ - iter_ranges(): CodePointRangeIterator; - - /** - - * Produces an iterator over ranges of code points not contained in this set - - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/struct.CodePointSetDataBorrowed.html#method.iter_ranges_complemented Rust documentation for `iter_ranges_complemented`} for more information. - */ - iter_ranges_complemented(): CodePointRangeIterator; - - /** - - * which is a mask with the same format as the `U_GC_XX_MASK` mask in ICU4C - - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/fn.for_general_category_group.html Rust documentation for `for_general_category_group`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_for_general_category_group(provider: DataProvider, group: u32): CodePointSetData | never; - - /** - - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/fn.ascii_hex_digit.html Rust documentation for `ascii_hex_digit`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_ascii_hex_digit(provider: DataProvider): CodePointSetData | never; - - /** - - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/fn.alnum.html Rust documentation for `alnum`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_alnum(provider: DataProvider): CodePointSetData | never; - - /** - - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/fn.alphabetic.html Rust documentation for `alphabetic`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_alphabetic(provider: DataProvider): CodePointSetData | never; - - /** - - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/fn.bidi_control.html Rust documentation for `bidi_control`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_bidi_control(provider: DataProvider): CodePointSetData | never; - - /** - - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/fn.bidi_mirrored.html Rust documentation for `bidi_mirrored`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_bidi_mirrored(provider: DataProvider): CodePointSetData | never; - - /** - - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/fn.blank.html Rust documentation for `blank`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_blank(provider: DataProvider): CodePointSetData | never; - - /** - - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/fn.cased.html Rust documentation for `cased`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_cased(provider: DataProvider): CodePointSetData | never; - - /** - - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/fn.case_ignorable.html Rust documentation for `case_ignorable`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_case_ignorable(provider: DataProvider): CodePointSetData | never; - - /** - - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/fn.full_composition_exclusion.html Rust documentation for `full_composition_exclusion`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_full_composition_exclusion(provider: DataProvider): CodePointSetData | never; - - /** - - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/fn.changes_when_casefolded.html Rust documentation for `changes_when_casefolded`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_changes_when_casefolded(provider: DataProvider): CodePointSetData | never; - - /** - - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/fn.changes_when_casemapped.html Rust documentation for `changes_when_casemapped`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_changes_when_casemapped(provider: DataProvider): CodePointSetData | never; - - /** - - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/fn.changes_when_nfkc_casefolded.html Rust documentation for `changes_when_nfkc_casefolded`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_changes_when_nfkc_casefolded(provider: DataProvider): CodePointSetData | never; - - /** - - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/fn.changes_when_lowercased.html Rust documentation for `changes_when_lowercased`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_changes_when_lowercased(provider: DataProvider): CodePointSetData | never; - - /** - - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/fn.changes_when_titlecased.html Rust documentation for `changes_when_titlecased`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_changes_when_titlecased(provider: DataProvider): CodePointSetData | never; - - /** - - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/fn.changes_when_uppercased.html Rust documentation for `changes_when_uppercased`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_changes_when_uppercased(provider: DataProvider): CodePointSetData | never; - - /** - - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/fn.dash.html Rust documentation for `dash`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_dash(provider: DataProvider): CodePointSetData | never; - - /** - - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/fn.deprecated.html Rust documentation for `deprecated`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_deprecated(provider: DataProvider): CodePointSetData | never; - - /** - - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/fn.default_ignorable_code_point.html Rust documentation for `default_ignorable_code_point`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_default_ignorable_code_point(provider: DataProvider): CodePointSetData | never; - - /** - - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/fn.diacritic.html Rust documentation for `diacritic`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_diacritic(provider: DataProvider): CodePointSetData | never; - - /** - - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/fn.emoji_modifier_base.html Rust documentation for `emoji_modifier_base`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_emoji_modifier_base(provider: DataProvider): CodePointSetData | never; - - /** - - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/fn.emoji_component.html Rust documentation for `emoji_component`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_emoji_component(provider: DataProvider): CodePointSetData | never; - - /** - - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/fn.emoji_modifier.html Rust documentation for `emoji_modifier`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_emoji_modifier(provider: DataProvider): CodePointSetData | never; - - /** - - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/fn.emoji.html Rust documentation for `emoji`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_emoji(provider: DataProvider): CodePointSetData | never; - - /** - - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/fn.emoji_presentation.html Rust documentation for `emoji_presentation`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_emoji_presentation(provider: DataProvider): CodePointSetData | never; - - /** - - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/fn.extender.html Rust documentation for `extender`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_extender(provider: DataProvider): CodePointSetData | never; - - /** - - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/fn.extended_pictographic.html Rust documentation for `extended_pictographic`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_extended_pictographic(provider: DataProvider): CodePointSetData | never; - - /** - - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/fn.graph.html Rust documentation for `graph`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_graph(provider: DataProvider): CodePointSetData | never; - - /** - - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/fn.grapheme_base.html Rust documentation for `grapheme_base`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_grapheme_base(provider: DataProvider): CodePointSetData | never; - - /** - - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/fn.grapheme_extend.html Rust documentation for `grapheme_extend`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_grapheme_extend(provider: DataProvider): CodePointSetData | never; - - /** - - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/fn.grapheme_link.html Rust documentation for `grapheme_link`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_grapheme_link(provider: DataProvider): CodePointSetData | never; - - /** + get ffiValue(): pointer; - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/fn.hex_digit.html Rust documentation for `hex_digit`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_hex_digit(provider: DataProvider): CodePointSetData | never; - /** + contains(cp: char): boolean; - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/fn.hyphen.html Rust documentation for `hyphen`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_hyphen(provider: DataProvider): CodePointSetData | never; + iterRanges(): CodePointRangeIterator; - /** + iterRangesComplemented(): CodePointRangeIterator; - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/fn.id_continue.html Rust documentation for `id_continue`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_id_continue(provider: DataProvider): CodePointSetData | never; + static loadForGeneralCategoryGroup(provider: DataProvider, group: number): CodePointSetData; - /** + static loadAsciiHexDigit(provider: DataProvider): CodePointSetData; - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/fn.ideographic.html Rust documentation for `ideographic`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_ideographic(provider: DataProvider): CodePointSetData | never; + static loadAlnum(provider: DataProvider): CodePointSetData; - /** + static loadAlphabetic(provider: DataProvider): CodePointSetData; - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/fn.id_start.html Rust documentation for `id_start`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_id_start(provider: DataProvider): CodePointSetData | never; + static loadBidiControl(provider: DataProvider): CodePointSetData; - /** + static loadBidiMirrored(provider: DataProvider): CodePointSetData; - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/fn.ids_binary_operator.html Rust documentation for `ids_binary_operator`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_ids_binary_operator(provider: DataProvider): CodePointSetData | never; + static loadBlank(provider: DataProvider): CodePointSetData; - /** + static loadCased(provider: DataProvider): CodePointSetData; - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/fn.ids_trinary_operator.html Rust documentation for `ids_trinary_operator`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_ids_trinary_operator(provider: DataProvider): CodePointSetData | never; + static loadCaseIgnorable(provider: DataProvider): CodePointSetData; - /** + static loadFullCompositionExclusion(provider: DataProvider): CodePointSetData; - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/fn.join_control.html Rust documentation for `join_control`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_join_control(provider: DataProvider): CodePointSetData | never; + static loadChangesWhenCasefolded(provider: DataProvider): CodePointSetData; - /** + static loadChangesWhenCasemapped(provider: DataProvider): CodePointSetData; - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/fn.logical_order_exception.html Rust documentation for `logical_order_exception`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_logical_order_exception(provider: DataProvider): CodePointSetData | never; + static loadChangesWhenNfkcCasefolded(provider: DataProvider): CodePointSetData; - /** + static loadChangesWhenLowercased(provider: DataProvider): CodePointSetData; - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/fn.lowercase.html Rust documentation for `lowercase`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_lowercase(provider: DataProvider): CodePointSetData | never; + static loadChangesWhenTitlecased(provider: DataProvider): CodePointSetData; - /** + static loadChangesWhenUppercased(provider: DataProvider): CodePointSetData; - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/fn.math.html Rust documentation for `math`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_math(provider: DataProvider): CodePointSetData | never; + static loadDash(provider: DataProvider): CodePointSetData; - /** + static loadDeprecated(provider: DataProvider): CodePointSetData; - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/fn.noncharacter_code_point.html Rust documentation for `noncharacter_code_point`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_noncharacter_code_point(provider: DataProvider): CodePointSetData | never; + static loadDefaultIgnorableCodePoint(provider: DataProvider): CodePointSetData; - /** + static loadDiacritic(provider: DataProvider): CodePointSetData; - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/fn.nfc_inert.html Rust documentation for `nfc_inert`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_nfc_inert(provider: DataProvider): CodePointSetData | never; + static loadEmojiModifierBase(provider: DataProvider): CodePointSetData; - /** + static loadEmojiComponent(provider: DataProvider): CodePointSetData; - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/fn.nfd_inert.html Rust documentation for `nfd_inert`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_nfd_inert(provider: DataProvider): CodePointSetData | never; + static loadEmojiModifier(provider: DataProvider): CodePointSetData; - /** + static loadEmoji(provider: DataProvider): CodePointSetData; - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/fn.nfkc_inert.html Rust documentation for `nfkc_inert`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_nfkc_inert(provider: DataProvider): CodePointSetData | never; + static loadEmojiPresentation(provider: DataProvider): CodePointSetData; - /** + static loadExtender(provider: DataProvider): CodePointSetData; - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/fn.nfkd_inert.html Rust documentation for `nfkd_inert`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_nfkd_inert(provider: DataProvider): CodePointSetData | never; + static loadExtendedPictographic(provider: DataProvider): CodePointSetData; - /** + static loadGraph(provider: DataProvider): CodePointSetData; - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/fn.pattern_syntax.html Rust documentation for `pattern_syntax`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_pattern_syntax(provider: DataProvider): CodePointSetData | never; + static loadGraphemeBase(provider: DataProvider): CodePointSetData; - /** + static loadGraphemeExtend(provider: DataProvider): CodePointSetData; - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/fn.pattern_white_space.html Rust documentation for `pattern_white_space`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_pattern_white_space(provider: DataProvider): CodePointSetData | never; + static loadGraphemeLink(provider: DataProvider): CodePointSetData; - /** + static loadHexDigit(provider: DataProvider): CodePointSetData; - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/fn.prepended_concatenation_mark.html Rust documentation for `prepended_concatenation_mark`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_prepended_concatenation_mark(provider: DataProvider): CodePointSetData | never; + static loadHyphen(provider: DataProvider): CodePointSetData; - /** + static loadIdContinue(provider: DataProvider): CodePointSetData; - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/fn.print.html Rust documentation for `print`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_print(provider: DataProvider): CodePointSetData | never; + static loadIdeographic(provider: DataProvider): CodePointSetData; - /** + static loadIdStart(provider: DataProvider): CodePointSetData; - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/fn.quotation_mark.html Rust documentation for `quotation_mark`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_quotation_mark(provider: DataProvider): CodePointSetData | never; + static loadIdsBinaryOperator(provider: DataProvider): CodePointSetData; - /** + static loadIdsTrinaryOperator(provider: DataProvider): CodePointSetData; - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/fn.radical.html Rust documentation for `radical`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_radical(provider: DataProvider): CodePointSetData | never; + static loadJoinControl(provider: DataProvider): CodePointSetData; - /** + static loadLogicalOrderException(provider: DataProvider): CodePointSetData; - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/fn.regional_indicator.html Rust documentation for `regional_indicator`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_regional_indicator(provider: DataProvider): CodePointSetData | never; + static loadLowercase(provider: DataProvider): CodePointSetData; - /** + static loadMath(provider: DataProvider): CodePointSetData; - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/fn.soft_dotted.html Rust documentation for `soft_dotted`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_soft_dotted(provider: DataProvider): CodePointSetData | never; + static loadNoncharacterCodePoint(provider: DataProvider): CodePointSetData; - /** + static loadNfcInert(provider: DataProvider): CodePointSetData; - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/fn.segment_starter.html Rust documentation for `segment_starter`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_segment_starter(provider: DataProvider): CodePointSetData | never; + static loadNfdInert(provider: DataProvider): CodePointSetData; - /** + static loadNfkcInert(provider: DataProvider): CodePointSetData; - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/fn.case_sensitive.html Rust documentation for `case_sensitive`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_case_sensitive(provider: DataProvider): CodePointSetData | never; + static loadNfkdInert(provider: DataProvider): CodePointSetData; - /** + static loadPatternSyntax(provider: DataProvider): CodePointSetData; - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/fn.sentence_terminal.html Rust documentation for `sentence_terminal`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_sentence_terminal(provider: DataProvider): CodePointSetData | never; + static loadPatternWhiteSpace(provider: DataProvider): CodePointSetData; - /** + static loadPrependedConcatenationMark(provider: DataProvider): CodePointSetData; - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/fn.terminal_punctuation.html Rust documentation for `terminal_punctuation`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_terminal_punctuation(provider: DataProvider): CodePointSetData | never; + static loadPrint(provider: DataProvider): CodePointSetData; - /** + static loadQuotationMark(provider: DataProvider): CodePointSetData; - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/fn.unified_ideograph.html Rust documentation for `unified_ideograph`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_unified_ideograph(provider: DataProvider): CodePointSetData | never; + static loadRadical(provider: DataProvider): CodePointSetData; - /** + static loadRegionalIndicator(provider: DataProvider): CodePointSetData; - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/fn.uppercase.html Rust documentation for `uppercase`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_uppercase(provider: DataProvider): CodePointSetData | never; + static loadSoftDotted(provider: DataProvider): CodePointSetData; - /** + static loadSegmentStarter(provider: DataProvider): CodePointSetData; - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/fn.variation_selector.html Rust documentation for `variation_selector`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_variation_selector(provider: DataProvider): CodePointSetData | never; + static loadCaseSensitive(provider: DataProvider): CodePointSetData; - /** + static loadSentenceTerminal(provider: DataProvider): CodePointSetData; - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/fn.white_space.html Rust documentation for `white_space`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_white_space(provider: DataProvider): CodePointSetData | never; + static loadTerminalPunctuation(provider: DataProvider): CodePointSetData; - /** + static loadUnifiedIdeograph(provider: DataProvider): CodePointSetData; - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/fn.xdigit.html Rust documentation for `xdigit`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_xdigit(provider: DataProvider): CodePointSetData | never; + static loadUppercase(provider: DataProvider): CodePointSetData; - /** + static loadVariationSelector(provider: DataProvider): CodePointSetData; - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/fn.xid_continue.html Rust documentation for `xid_continue`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_xid_continue(provider: DataProvider): CodePointSetData | never; + static loadWhiteSpace(provider: DataProvider): CodePointSetData; - /** + static loadXdigit(provider: DataProvider): CodePointSetData; - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/fn.xid_start.html Rust documentation for `xid_start`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_xid_start(provider: DataProvider): CodePointSetData | never; + static loadXidContinue(provider: DataProvider): CodePointSetData; - /** + static loadXidStart(provider: DataProvider): CodePointSetData; - * Loads data for a property specified as a string as long as it is one of the {@link https://tc39.es/ecma262/#table-binary-unicode-properties ECMA-262 binary properties} (not including Any, ASCII, and Assigned pseudoproperties). + static loadForEcma262(provider: DataProvider, propertyName: string): CodePointSetData; - * Returns `Error::PropertyUnexpectedPropertyNameError` in case the string does not match any property in the list + - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/fn.for_ecma262.html Rust documentation for `for_ecma262`} for more information. - * @throws {@link FFIError}<{@link Error}> - */ - static load_for_ecma262(provider: DataProvider, property_name: string): CodePointSetData | never; -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/CodePointSetData.mjs b/ffi/capi/bindings/js/CodePointSetData.mjs index 986f65856be..d0262318e84 100644 --- a/ffi/capi/bindings/js/CodePointSetData.mjs +++ b/ffi/capi/bindings/js/CodePointSetData.mjs @@ -1,1178 +1,1362 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" +// generated by diplomat-tool import { CodePointRangeIterator } from "./CodePointRangeIterator.mjs" -import { DataError_js_to_rust, DataError_rust_to_js } from "./DataError.mjs" -import { Error_js_to_rust, Error_rust_to_js } from "./Error.mjs" - -const CodePointSetData_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XCodePointSetData_destroy(underlying); +import { DataError } from "./DataError.mjs" +import { DataProvider } from "./DataProvider.mjs" +import { Error } from "./Error.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; + + +/** An ICU4X Unicode Set Property object, capable of querying whether a code point is contained in a set based on a Unicode property. +* +*See the [Rust documentation for `properties`](https://docs.rs/icu/latest/icu/properties/index.html) for more information. +* +*See the [Rust documentation for `CodePointSetData`](https://docs.rs/icu/latest/icu/properties/sets/struct.CodePointSetData.html) for more information. +* +*See the [Rust documentation for `CodePointSetDataBorrowed`](https://docs.rs/icu/latest/icu/properties/sets/struct.CodePointSetDataBorrowed.html) for more information. +*/ + +const CodePointSetData_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XCodePointSetData_destroy(ptr); }); - export class CodePointSetData { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - CodePointSetData_box_destroy_registry.register(this, underlying); - } - } - - contains(arg_cp) { - return wasm.ICU4XCodePointSetData_contains(this.underlying, diplomatRuntime.extractCodePoint(arg_cp, 'arg_cp')); - } - - contains32(arg_cp) { - return wasm.ICU4XCodePointSetData_contains32(this.underlying, arg_cp); - } - - iter_ranges() { - return new CodePointRangeIterator(wasm.ICU4XCodePointSetData_iter_ranges(this.underlying), true, [this]); - } - - iter_ranges_complemented() { - return new CodePointRangeIterator(wasm.ICU4XCodePointSetData_iter_ranges_complemented(this.underlying), true, [this]); - } - - static load_for_general_category_group(arg_provider, arg_group) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointSetData_load_for_general_category_group(diplomat_receive_buffer, arg_provider.underlying, arg_group); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_ascii_hex_digit(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointSetData_load_ascii_hex_digit(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_alnum(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointSetData_load_alnum(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_alphabetic(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointSetData_load_alphabetic(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_bidi_control(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointSetData_load_bidi_control(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_bidi_mirrored(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointSetData_load_bidi_mirrored(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_blank(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointSetData_load_blank(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_cased(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointSetData_load_cased(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_case_ignorable(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointSetData_load_case_ignorable(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_full_composition_exclusion(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointSetData_load_full_composition_exclusion(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_changes_when_casefolded(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointSetData_load_changes_when_casefolded(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_changes_when_casemapped(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointSetData_load_changes_when_casemapped(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_changes_when_nfkc_casefolded(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointSetData_load_changes_when_nfkc_casefolded(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_changes_when_lowercased(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointSetData_load_changes_when_lowercased(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_changes_when_titlecased(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointSetData_load_changes_when_titlecased(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_changes_when_uppercased(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointSetData_load_changes_when_uppercased(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_dash(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointSetData_load_dash(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_deprecated(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointSetData_load_deprecated(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_default_ignorable_code_point(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointSetData_load_default_ignorable_code_point(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_diacritic(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointSetData_load_diacritic(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_emoji_modifier_base(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointSetData_load_emoji_modifier_base(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_emoji_component(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointSetData_load_emoji_component(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_emoji_modifier(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointSetData_load_emoji_modifier(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_emoji(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointSetData_load_emoji(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_emoji_presentation(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointSetData_load_emoji_presentation(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_extender(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointSetData_load_extender(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_extended_pictographic(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointSetData_load_extended_pictographic(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_graph(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointSetData_load_graph(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_grapheme_base(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointSetData_load_grapheme_base(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_grapheme_extend(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointSetData_load_grapheme_extend(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_grapheme_link(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointSetData_load_grapheme_link(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_hex_digit(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointSetData_load_hex_digit(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_hyphen(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointSetData_load_hyphen(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_id_continue(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointSetData_load_id_continue(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_ideographic(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointSetData_load_ideographic(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_id_start(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointSetData_load_id_start(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_ids_binary_operator(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointSetData_load_ids_binary_operator(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_ids_trinary_operator(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointSetData_load_ids_trinary_operator(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_join_control(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointSetData_load_join_control(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_logical_order_exception(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointSetData_load_logical_order_exception(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_lowercase(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointSetData_load_lowercase(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_math(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointSetData_load_math(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_noncharacter_code_point(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointSetData_load_noncharacter_code_point(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_nfc_inert(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointSetData_load_nfc_inert(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_nfd_inert(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointSetData_load_nfd_inert(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_nfkc_inert(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointSetData_load_nfkc_inert(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_nfkd_inert(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointSetData_load_nfkd_inert(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_pattern_syntax(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointSetData_load_pattern_syntax(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_pattern_white_space(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointSetData_load_pattern_white_space(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_prepended_concatenation_mark(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointSetData_load_prepended_concatenation_mark(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_print(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointSetData_load_print(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_quotation_mark(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointSetData_load_quotation_mark(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_radical(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointSetData_load_radical(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_regional_indicator(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointSetData_load_regional_indicator(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_soft_dotted(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointSetData_load_soft_dotted(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_segment_starter(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointSetData_load_segment_starter(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_case_sensitive(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointSetData_load_case_sensitive(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_sentence_terminal(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointSetData_load_sentence_terminal(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_terminal_punctuation(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointSetData_load_terminal_punctuation(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_unified_ideograph(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointSetData_load_unified_ideograph(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_uppercase(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointSetData_load_uppercase(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_variation_selector(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointSetData_load_variation_selector(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_white_space(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointSetData_load_white_space(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_xdigit(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointSetData_load_xdigit(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_xid_continue(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointSetData_load_xid_continue(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_xid_start(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointSetData_load_xid_start(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_for_ecma262(arg_provider, arg_property_name) { - const buf_arg_property_name = diplomatRuntime.DiplomatBuf.str8(wasm, arg_property_name); - const diplomat_out = (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCodePointSetData_load_for_ecma262(diplomat_receive_buffer, arg_provider.underlying, buf_arg_property_name.ptr, buf_arg_property_name.size); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = Error_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - buf_arg_property_name.free(); - return diplomat_out; - } -} + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + + constructor(ptr, selfEdge) { + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + CodePointSetData_box_destroy_registry.register(this, this.#ptr); + } + + get ffiValue() { + return this.#ptr; + } + + + contains(cp) { + const result = wasm.ICU4XCodePointSetData_contains(this.ffiValue, diplomatRuntime.extractCodePoint(cp, 'cp')); + + try { + + return result; + } finally { + + } + } + + iterRanges() { + + // This lifetime edge depends on lifetimes 'a + let aEdges = [this]; + const result = wasm.ICU4XCodePointSetData_iter_ranges(this.ffiValue); + + try { + + return new CodePointRangeIterator(result, [], aEdges); + } finally { + + } + } + + iterRangesComplemented() { + + // This lifetime edge depends on lifetimes 'a + let aEdges = [this]; + const result = wasm.ICU4XCodePointSetData_iter_ranges_complemented(this.ffiValue); + + try { + + return new CodePointRangeIterator(result, [], aEdges); + } finally { + + } + } + + static loadForGeneralCategoryGroup(provider, group) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointSetData_load_for_general_category_group(diplomat_receive_buffer, provider.ffiValue, group); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadAsciiHexDigit(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointSetData_load_ascii_hex_digit(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadAlnum(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointSetData_load_alnum(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadAlphabetic(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointSetData_load_alphabetic(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadBidiControl(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointSetData_load_bidi_control(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadBidiMirrored(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointSetData_load_bidi_mirrored(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadBlank(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointSetData_load_blank(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadCased(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointSetData_load_cased(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadCaseIgnorable(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointSetData_load_case_ignorable(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadFullCompositionExclusion(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointSetData_load_full_composition_exclusion(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadChangesWhenCasefolded(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointSetData_load_changes_when_casefolded(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadChangesWhenCasemapped(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointSetData_load_changes_when_casemapped(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadChangesWhenNfkcCasefolded(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointSetData_load_changes_when_nfkc_casefolded(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadChangesWhenLowercased(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointSetData_load_changes_when_lowercased(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadChangesWhenTitlecased(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointSetData_load_changes_when_titlecased(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadChangesWhenUppercased(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointSetData_load_changes_when_uppercased(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadDash(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointSetData_load_dash(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadDeprecated(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointSetData_load_deprecated(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadDefaultIgnorableCodePoint(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointSetData_load_default_ignorable_code_point(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadDiacritic(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointSetData_load_diacritic(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadEmojiModifierBase(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointSetData_load_emoji_modifier_base(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadEmojiComponent(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointSetData_load_emoji_component(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadEmojiModifier(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointSetData_load_emoji_modifier(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadEmoji(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointSetData_load_emoji(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadEmojiPresentation(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointSetData_load_emoji_presentation(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadExtender(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointSetData_load_extender(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadExtendedPictographic(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointSetData_load_extended_pictographic(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadGraph(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointSetData_load_graph(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadGraphemeBase(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointSetData_load_grapheme_base(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadGraphemeExtend(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointSetData_load_grapheme_extend(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadGraphemeLink(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointSetData_load_grapheme_link(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadHexDigit(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointSetData_load_hex_digit(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadHyphen(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointSetData_load_hyphen(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadIdContinue(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointSetData_load_id_continue(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadIdeographic(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointSetData_load_ideographic(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadIdStart(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointSetData_load_id_start(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadIdsBinaryOperator(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointSetData_load_ids_binary_operator(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadIdsTrinaryOperator(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointSetData_load_ids_trinary_operator(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadJoinControl(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointSetData_load_join_control(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadLogicalOrderException(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointSetData_load_logical_order_exception(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadLowercase(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointSetData_load_lowercase(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadMath(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointSetData_load_math(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadNoncharacterCodePoint(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointSetData_load_noncharacter_code_point(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadNfcInert(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointSetData_load_nfc_inert(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadNfdInert(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointSetData_load_nfd_inert(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadNfkcInert(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointSetData_load_nfkc_inert(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadNfkdInert(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointSetData_load_nfkd_inert(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadPatternSyntax(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointSetData_load_pattern_syntax(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadPatternWhiteSpace(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointSetData_load_pattern_white_space(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadPrependedConcatenationMark(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointSetData_load_prepended_concatenation_mark(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadPrint(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointSetData_load_print(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadQuotationMark(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointSetData_load_quotation_mark(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadRadical(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointSetData_load_radical(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadRegionalIndicator(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointSetData_load_regional_indicator(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadSoftDotted(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointSetData_load_soft_dotted(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadSegmentStarter(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointSetData_load_segment_starter(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadCaseSensitive(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointSetData_load_case_sensitive(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadSentenceTerminal(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointSetData_load_sentence_terminal(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadTerminalPunctuation(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointSetData_load_terminal_punctuation(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadUnifiedIdeograph(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointSetData_load_unified_ideograph(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadUppercase(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointSetData_load_uppercase(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadVariationSelector(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointSetData_load_variation_selector(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadWhiteSpace(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointSetData_load_white_space(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadXdigit(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointSetData_load_xdigit(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadXidContinue(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointSetData_load_xid_continue(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadXidStart(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointSetData_load_xid_start(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadForEcma262(provider, propertyName) { + + const propertyNameSlice = diplomatRuntime.DiplomatBuf.str8(wasm, propertyName); + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCodePointSetData_load_for_ecma262(diplomat_receive_buffer, provider.ffiValue, propertyNameSlice.ptr, propertyNameSlice.size); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = (() => {for (let i of Error.values) { if(i[1] === diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)) return Error[i[0]]; } return null;})(); + throw new Error('Error: ' + cause.value, { cause }); + } + return new CodePointSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + propertyNameSlice.free(); + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/Collator.d.ts b/ffi/capi/bindings/js/Collator.d.ts index cc0845f8ce2..f5c7af3fbbf 100644 --- a/ffi/capi/bindings/js/Collator.d.ts +++ b/ffi/capi/bindings/js/Collator.d.ts @@ -1,59 +1,25 @@ -import { FFIError } from "./diplomat-runtime" -import { CollatorOptionsV1 } from "./CollatorOptionsV1"; -import { CollatorResolvedOptionsV1 } from "./CollatorResolvedOptionsV1"; -import { DataError } from "./DataError"; -import { DataProvider } from "./DataProvider"; -import { Locale } from "./Locale"; -import { Ordering } from "./Ordering"; - -/** - - * See the {@link https://docs.rs/icu/latest/icu/collator/struct.Collator.html Rust documentation for `Collator`} for more information. - */ -export class Collator { - - /** - - * Construct a new Collator instance. - - * See the {@link https://docs.rs/icu/latest/icu/collator/struct.Collator.html#method.try_new Rust documentation for `try_new`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static create_v1(provider: DataProvider, locale: Locale, options: CollatorOptionsV1): Collator | never; - - /** +// generated by diplomat-tool +import type { CollatorOptions } from "./CollatorOptions" +import type { DataProvider } from "./DataProvider" +import type { Locale } from "./Locale" +import type { ResolvedCollatorOptions } from "./ResolvedCollatorOptions" +import type { pointer, char } from "./diplomat-runtime.d.ts"; - * Compare two strings. - * Ill-formed input is treated as if errors had been replaced with REPLACEMENT CHARACTERs according to the WHATWG Encoding Standard. - - * See the {@link https://docs.rs/icu/latest/icu/collator/struct.Collator.html#method.compare_utf8 Rust documentation for `compare_utf8`} for more information. - */ - compare(left: string, right: string): Ordering; - - /** - - * Compare two strings. - - * See the {@link https://docs.rs/icu/latest/icu/collator/struct.Collator.html#method.compare Rust documentation for `compare`} for more information. - */ - compare_valid_utf8(left: string, right: string): Ordering; +/** See the [Rust documentation for `Collator`](https://docs.rs/icu/latest/icu/collator/struct.Collator.html) for more information. +*/ +export class Collator { + - /** + get ffiValue(): pointer; - * Compare two strings. - * Ill-formed input is treated as if errors had been replaced with REPLACEMENT CHARACTERs according to the WHATWG Encoding Standard. + static create(provider: DataProvider, locale: Locale, options: CollatorOptions): Collator; - * See the {@link https://docs.rs/icu/latest/icu/collator/struct.Collator.html#method.compare_utf16 Rust documentation for `compare_utf16`} for more information. - */ - compare_utf16(left: string, right: string): Ordering; + compare(left: string, right: string): number; - /** + get resolvedOptions(): ResolvedCollatorOptions; - * The resolved options showing how the default options, the requested options, and the options from locale data were combined. None of the struct fields will have `Auto` as the value. + - * See the {@link https://docs.rs/icu/latest/icu/collator/struct.Collator.html#method.resolved_options Rust documentation for `resolved_options`} for more information. - */ - resolved_options(): CollatorResolvedOptionsV1; -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/Collator.mjs b/ffi/capi/bindings/js/Collator.mjs index b9972504d13..390faa128d8 100644 --- a/ffi/capi/bindings/js/Collator.mjs +++ b/ffi/capi/bindings/js/Collator.mjs @@ -1,88 +1,100 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" -import { CollatorAlternateHandling_js_to_rust, CollatorAlternateHandling_rust_to_js } from "./CollatorAlternateHandling.mjs" -import { CollatorBackwardSecondLevel_js_to_rust, CollatorBackwardSecondLevel_rust_to_js } from "./CollatorBackwardSecondLevel.mjs" -import { CollatorCaseFirst_js_to_rust, CollatorCaseFirst_rust_to_js } from "./CollatorCaseFirst.mjs" -import { CollatorCaseLevel_js_to_rust, CollatorCaseLevel_rust_to_js } from "./CollatorCaseLevel.mjs" -import { CollatorMaxVariable_js_to_rust, CollatorMaxVariable_rust_to_js } from "./CollatorMaxVariable.mjs" -import { CollatorNumeric_js_to_rust, CollatorNumeric_rust_to_js } from "./CollatorNumeric.mjs" -import { CollatorResolvedOptionsV1 } from "./CollatorResolvedOptionsV1.mjs" -import { CollatorStrength_js_to_rust, CollatorStrength_rust_to_js } from "./CollatorStrength.mjs" -import { DataError_js_to_rust, DataError_rust_to_js } from "./DataError.mjs" -import { Ordering_js_to_rust, Ordering_rust_to_js } from "./Ordering.mjs" +// generated by diplomat-tool +import { CollatorOptions } from "./CollatorOptions.mjs" +import { DataError } from "./DataError.mjs" +import { DataProvider } from "./DataProvider.mjs" +import { Locale } from "./Locale.mjs" +import { ResolvedCollatorOptions } from "./ResolvedCollatorOptions.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -const Collator_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XCollator_destroy(underlying); -}); +/** See the [Rust documentation for `Collator`](https://docs.rs/icu/latest/icu/collator/struct.Collator.html) for more information. +*/ + +const Collator_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XCollator_destroy(ptr); +}); export class Collator { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - Collator_box_destroy_registry.register(this, underlying); + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + + constructor(ptr, selfEdge) { + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + Collator_box_destroy_registry.register(this, this.#ptr); + } + + get ffiValue() { + return this.#ptr; } - } - static create_v1(arg_provider, arg_locale, arg_options) { - const field_strength_arg_options = arg_options["strength"]; - const field_alternate_handling_arg_options = arg_options["alternate_handling"]; - const field_case_first_arg_options = arg_options["case_first"]; - const field_max_variable_arg_options = arg_options["max_variable"]; - const field_case_level_arg_options = arg_options["case_level"]; - const field_numeric_arg_options = arg_options["numeric"]; - const field_backward_second_level_arg_options = arg_options["backward_second_level"]; - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCollator_create_v1(diplomat_receive_buffer, arg_provider.underlying, arg_locale.underlying, CollatorStrength_js_to_rust[field_strength_arg_options], CollatorAlternateHandling_js_to_rust[field_alternate_handling_arg_options], CollatorCaseFirst_js_to_rust[field_case_first_arg_options], CollatorMaxVariable_js_to_rust[field_max_variable_arg_options], CollatorCaseLevel_js_to_rust[field_case_level_arg_options], CollatorNumeric_js_to_rust[field_numeric_arg_options], CollatorBackwardSecondLevel_js_to_rust[field_backward_second_level_arg_options]); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new Collator(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - compare(arg_left, arg_right) { - const buf_arg_left = diplomatRuntime.DiplomatBuf.str8(wasm, arg_left); - const buf_arg_right = diplomatRuntime.DiplomatBuf.str8(wasm, arg_right); - const diplomat_out = Ordering_rust_to_js[wasm.ICU4XCollator_compare(this.underlying, buf_arg_left.ptr, buf_arg_left.size, buf_arg_right.ptr, buf_arg_right.size)]; - buf_arg_left.free(); - buf_arg_right.free(); - return diplomat_out; - } + static create(provider, locale, options) { + + let slice_cleanup_callbacks = []; + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCollator_create_v1(diplomat_receive_buffer, provider.ffiValue, locale.ffiValue, ...options._intoFFI(slice_cleanup_callbacks, {})); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new Collator(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + for (let cleanup of slice_cleanup_callbacks) { + cleanup(); + } + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } - compare_valid_utf8(arg_left, arg_right) { - const buf_arg_left = diplomatRuntime.DiplomatBuf.str8(wasm, arg_left); - const buf_arg_right = diplomatRuntime.DiplomatBuf.str8(wasm, arg_right); - const diplomat_out = Ordering_rust_to_js[wasm.ICU4XCollator_compare_valid_utf8(this.underlying, buf_arg_left.ptr, buf_arg_left.size, buf_arg_right.ptr, buf_arg_right.size)]; - buf_arg_left.free(); - buf_arg_right.free(); - return diplomat_out; - } + compare(left, right) { + + const leftSlice = diplomatRuntime.DiplomatBuf.str16(wasm, left); + + const rightSlice = diplomatRuntime.DiplomatBuf.str16(wasm, right); + const result = wasm.ICU4XCollator_compare_utf16(this.ffiValue, leftSlice.ptr, leftSlice.size, rightSlice.ptr, rightSlice.size); + + try { + + return result; + } finally { + + leftSlice.free(); + + rightSlice.free(); + + } + } + + get resolvedOptions() { + + const diplomat_receive_buffer = wasm.diplomat_alloc(28, 4); + const result = wasm.ICU4XCollator_resolved_options(diplomat_receive_buffer, this.ffiValue); + + try { + + return new ResolvedCollatorOptions(diplomat_receive_buffer); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 28, 4); + + } + } - compare_utf16(arg_left, arg_right) { - const buf_arg_left = diplomatRuntime.DiplomatBuf.str16(wasm, arg_left); - const buf_arg_right = diplomatRuntime.DiplomatBuf.str16(wasm, arg_right); - const diplomat_out = Ordering_rust_to_js[wasm.ICU4XCollator_compare_utf16(this.underlying, buf_arg_left.ptr, buf_arg_left.size, buf_arg_right.ptr, buf_arg_right.size)]; - buf_arg_left.free(); - buf_arg_right.free(); - return diplomat_out; - } + - resolved_options() { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(28, 4); - wasm.ICU4XCollator_resolved_options(diplomat_receive_buffer, this.underlying); - const out = new CollatorResolvedOptionsV1(diplomat_receive_buffer); - wasm.diplomat_free(diplomat_receive_buffer, 28, 4); - return out; - })(); - } -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/CollatorAlternateHandling.d.ts b/ffi/capi/bindings/js/CollatorAlternateHandling.d.ts index c7ef6089d1f..f003d9b47d4 100644 --- a/ffi/capi/bindings/js/CollatorAlternateHandling.d.ts +++ b/ffi/capi/bindings/js/CollatorAlternateHandling.d.ts @@ -1,16 +1,23 @@ +// generated by diplomat-tool +import type { pointer, char } from "./diplomat-runtime.d.ts"; + +// Base enumerator definition +/** See the [Rust documentation for `AlternateHandling`](https://docs.rs/icu/latest/icu/collator/enum.AlternateHandling.html) for more information. +*/ +export class CollatorAlternateHandling { + constructor(value : CollatorAlternateHandling | string); + + get value() : string; + + get ffiValue() : number; + + static Auto : CollatorAlternateHandling; + + static NonIgnorable : CollatorAlternateHandling; + + static Shifted : CollatorAlternateHandling; + + + -/** - - * See the {@link https://docs.rs/icu/latest/icu/collator/enum.AlternateHandling.html Rust documentation for `AlternateHandling`} for more information. - */ -export enum CollatorAlternateHandling { - /** - */ - Auto = 'Auto', - /** - */ - NonIgnorable = 'NonIgnorable', - /** - */ - Shifted = 'Shifted', } \ No newline at end of file diff --git a/ffi/capi/bindings/js/CollatorAlternateHandling.mjs b/ffi/capi/bindings/js/CollatorAlternateHandling.mjs index 72cc7ba9865..8fbe528e3e2 100644 --- a/ffi/capi/bindings/js/CollatorAlternateHandling.mjs +++ b/ffi/capi/bindings/js/CollatorAlternateHandling.mjs @@ -1,20 +1,47 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" - -export const CollatorAlternateHandling_js_to_rust = { - "Auto": 0, - "NonIgnorable": 1, - "Shifted": 2, -}; - -export const CollatorAlternateHandling_rust_to_js = { - [0]: "Auto", - [1]: "NonIgnorable", - [2]: "Shifted", -}; - -export const CollatorAlternateHandling = { - "Auto": "Auto", - "NonIgnorable": "NonIgnorable", - "Shifted": "Shifted", -}; +// generated by diplomat-tool +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; + +// Base enumerator definition +/** See the [Rust documentation for `AlternateHandling`](https://docs.rs/icu/latest/icu/collator/enum.AlternateHandling.html) for more information. +*/ +export class CollatorAlternateHandling { + #value = undefined; + + static values = new Map([ + ["Auto", 0], + ["NonIgnorable", 1], + ["Shifted", 2] + ]); + constructor(value) { + if (value instanceof CollatorAlternateHandling) { + this.#value = value.value; + return; + } + + if (CollatorAlternateHandling.values.has(value)) { + this.#value = value; + return; + } + + throw TypeError(value + " is not a CollatorAlternateHandling and does not correspond to any of its enumerator values."); + } + + get value() { + return this.#value; + } + + get ffiValue() { + return CollatorAlternateHandling.values.get(this.#value); + } + + static Auto = new CollatorAlternateHandling("Auto"); + + static NonIgnorable = new CollatorAlternateHandling("NonIgnorable"); + + static Shifted = new CollatorAlternateHandling("Shifted"); + + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/CollatorBackwardSecondLevel.d.ts b/ffi/capi/bindings/js/CollatorBackwardSecondLevel.d.ts index abe0d001319..a87f90201cd 100644 --- a/ffi/capi/bindings/js/CollatorBackwardSecondLevel.d.ts +++ b/ffi/capi/bindings/js/CollatorBackwardSecondLevel.d.ts @@ -1,16 +1,23 @@ +// generated by diplomat-tool +import type { pointer, char } from "./diplomat-runtime.d.ts"; + +// Base enumerator definition +/** See the [Rust documentation for `BackwardSecondLevel`](https://docs.rs/icu/latest/icu/collator/enum.BackwardSecondLevel.html) for more information. +*/ +export class CollatorBackwardSecondLevel { + constructor(value : CollatorBackwardSecondLevel | string); + + get value() : string; + + get ffiValue() : number; + + static Auto : CollatorBackwardSecondLevel; + + static Off : CollatorBackwardSecondLevel; + + static On : CollatorBackwardSecondLevel; + + + -/** - - * See the {@link https://docs.rs/icu/latest/icu/collator/enum.BackwardSecondLevel.html Rust documentation for `BackwardSecondLevel`} for more information. - */ -export enum CollatorBackwardSecondLevel { - /** - */ - Auto = 'Auto', - /** - */ - Off = 'Off', - /** - */ - On = 'On', } \ No newline at end of file diff --git a/ffi/capi/bindings/js/CollatorBackwardSecondLevel.mjs b/ffi/capi/bindings/js/CollatorBackwardSecondLevel.mjs index dd607190aaa..527701d3946 100644 --- a/ffi/capi/bindings/js/CollatorBackwardSecondLevel.mjs +++ b/ffi/capi/bindings/js/CollatorBackwardSecondLevel.mjs @@ -1,20 +1,47 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" - -export const CollatorBackwardSecondLevel_js_to_rust = { - "Auto": 0, - "Off": 1, - "On": 2, -}; - -export const CollatorBackwardSecondLevel_rust_to_js = { - [0]: "Auto", - [1]: "Off", - [2]: "On", -}; - -export const CollatorBackwardSecondLevel = { - "Auto": "Auto", - "Off": "Off", - "On": "On", -}; +// generated by diplomat-tool +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; + +// Base enumerator definition +/** See the [Rust documentation for `BackwardSecondLevel`](https://docs.rs/icu/latest/icu/collator/enum.BackwardSecondLevel.html) for more information. +*/ +export class CollatorBackwardSecondLevel { + #value = undefined; + + static values = new Map([ + ["Auto", 0], + ["Off", 1], + ["On", 2] + ]); + constructor(value) { + if (value instanceof CollatorBackwardSecondLevel) { + this.#value = value.value; + return; + } + + if (CollatorBackwardSecondLevel.values.has(value)) { + this.#value = value; + return; + } + + throw TypeError(value + " is not a CollatorBackwardSecondLevel and does not correspond to any of its enumerator values."); + } + + get value() { + return this.#value; + } + + get ffiValue() { + return CollatorBackwardSecondLevel.values.get(this.#value); + } + + static Auto = new CollatorBackwardSecondLevel("Auto"); + + static Off = new CollatorBackwardSecondLevel("Off"); + + static On = new CollatorBackwardSecondLevel("On"); + + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/CollatorCaseFirst.d.ts b/ffi/capi/bindings/js/CollatorCaseFirst.d.ts index 48e5350e33d..d37d6368edf 100644 --- a/ffi/capi/bindings/js/CollatorCaseFirst.d.ts +++ b/ffi/capi/bindings/js/CollatorCaseFirst.d.ts @@ -1,19 +1,25 @@ +// generated by diplomat-tool +import type { pointer, char } from "./diplomat-runtime.d.ts"; + +// Base enumerator definition +/** See the [Rust documentation for `CaseFirst`](https://docs.rs/icu/latest/icu/collator/enum.CaseFirst.html) for more information. +*/ +export class CollatorCaseFirst { + constructor(value : CollatorCaseFirst | string); + + get value() : string; + + get ffiValue() : number; + + static Auto : CollatorCaseFirst; + + static Off : CollatorCaseFirst; + + static LowerFirst : CollatorCaseFirst; + + static UpperFirst : CollatorCaseFirst; + + + -/** - - * See the {@link https://docs.rs/icu/latest/icu/collator/enum.CaseFirst.html Rust documentation for `CaseFirst`} for more information. - */ -export enum CollatorCaseFirst { - /** - */ - Auto = 'Auto', - /** - */ - Off = 'Off', - /** - */ - LowerFirst = 'LowerFirst', - /** - */ - UpperFirst = 'UpperFirst', } \ No newline at end of file diff --git a/ffi/capi/bindings/js/CollatorCaseFirst.mjs b/ffi/capi/bindings/js/CollatorCaseFirst.mjs index 06fdce25fac..ccf54b6c9c8 100644 --- a/ffi/capi/bindings/js/CollatorCaseFirst.mjs +++ b/ffi/capi/bindings/js/CollatorCaseFirst.mjs @@ -1,23 +1,50 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" - -export const CollatorCaseFirst_js_to_rust = { - "Auto": 0, - "Off": 1, - "LowerFirst": 2, - "UpperFirst": 3, -}; - -export const CollatorCaseFirst_rust_to_js = { - [0]: "Auto", - [1]: "Off", - [2]: "LowerFirst", - [3]: "UpperFirst", -}; - -export const CollatorCaseFirst = { - "Auto": "Auto", - "Off": "Off", - "LowerFirst": "LowerFirst", - "UpperFirst": "UpperFirst", -}; +// generated by diplomat-tool +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; + +// Base enumerator definition +/** See the [Rust documentation for `CaseFirst`](https://docs.rs/icu/latest/icu/collator/enum.CaseFirst.html) for more information. +*/ +export class CollatorCaseFirst { + #value = undefined; + + static values = new Map([ + ["Auto", 0], + ["Off", 1], + ["LowerFirst", 2], + ["UpperFirst", 3] + ]); + constructor(value) { + if (value instanceof CollatorCaseFirst) { + this.#value = value.value; + return; + } + + if (CollatorCaseFirst.values.has(value)) { + this.#value = value; + return; + } + + throw TypeError(value + " is not a CollatorCaseFirst and does not correspond to any of its enumerator values."); + } + + get value() { + return this.#value; + } + + get ffiValue() { + return CollatorCaseFirst.values.get(this.#value); + } + + static Auto = new CollatorCaseFirst("Auto"); + + static Off = new CollatorCaseFirst("Off"); + + static LowerFirst = new CollatorCaseFirst("LowerFirst"); + + static UpperFirst = new CollatorCaseFirst("UpperFirst"); + + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/CollatorCaseLevel.d.ts b/ffi/capi/bindings/js/CollatorCaseLevel.d.ts index 4d5be59788e..cb4410c7c99 100644 --- a/ffi/capi/bindings/js/CollatorCaseLevel.d.ts +++ b/ffi/capi/bindings/js/CollatorCaseLevel.d.ts @@ -1,16 +1,23 @@ +// generated by diplomat-tool +import type { pointer, char } from "./diplomat-runtime.d.ts"; + +// Base enumerator definition +/** See the [Rust documentation for `CaseLevel`](https://docs.rs/icu/latest/icu/collator/enum.CaseLevel.html) for more information. +*/ +export class CollatorCaseLevel { + constructor(value : CollatorCaseLevel | string); + + get value() : string; + + get ffiValue() : number; + + static Auto : CollatorCaseLevel; + + static Off : CollatorCaseLevel; + + static On : CollatorCaseLevel; + + + -/** - - * See the {@link https://docs.rs/icu/latest/icu/collator/enum.CaseLevel.html Rust documentation for `CaseLevel`} for more information. - */ -export enum CollatorCaseLevel { - /** - */ - Auto = 'Auto', - /** - */ - Off = 'Off', - /** - */ - On = 'On', } \ No newline at end of file diff --git a/ffi/capi/bindings/js/CollatorCaseLevel.mjs b/ffi/capi/bindings/js/CollatorCaseLevel.mjs index 7363511a60e..fc0d95459f3 100644 --- a/ffi/capi/bindings/js/CollatorCaseLevel.mjs +++ b/ffi/capi/bindings/js/CollatorCaseLevel.mjs @@ -1,20 +1,47 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" - -export const CollatorCaseLevel_js_to_rust = { - "Auto": 0, - "Off": 1, - "On": 2, -}; - -export const CollatorCaseLevel_rust_to_js = { - [0]: "Auto", - [1]: "Off", - [2]: "On", -}; - -export const CollatorCaseLevel = { - "Auto": "Auto", - "Off": "Off", - "On": "On", -}; +// generated by diplomat-tool +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; + +// Base enumerator definition +/** See the [Rust documentation for `CaseLevel`](https://docs.rs/icu/latest/icu/collator/enum.CaseLevel.html) for more information. +*/ +export class CollatorCaseLevel { + #value = undefined; + + static values = new Map([ + ["Auto", 0], + ["Off", 1], + ["On", 2] + ]); + constructor(value) { + if (value instanceof CollatorCaseLevel) { + this.#value = value.value; + return; + } + + if (CollatorCaseLevel.values.has(value)) { + this.#value = value; + return; + } + + throw TypeError(value + " is not a CollatorCaseLevel and does not correspond to any of its enumerator values."); + } + + get value() { + return this.#value; + } + + get ffiValue() { + return CollatorCaseLevel.values.get(this.#value); + } + + static Auto = new CollatorCaseLevel("Auto"); + + static Off = new CollatorCaseLevel("Off"); + + static On = new CollatorCaseLevel("On"); + + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/CollatorMaxVariable.d.ts b/ffi/capi/bindings/js/CollatorMaxVariable.d.ts index 45dd6e17186..4f7316b442a 100644 --- a/ffi/capi/bindings/js/CollatorMaxVariable.d.ts +++ b/ffi/capi/bindings/js/CollatorMaxVariable.d.ts @@ -1,22 +1,27 @@ +// generated by diplomat-tool +import type { pointer, char } from "./diplomat-runtime.d.ts"; + +// Base enumerator definition +/** See the [Rust documentation for `MaxVariable`](https://docs.rs/icu/latest/icu/collator/enum.MaxVariable.html) for more information. +*/ +export class CollatorMaxVariable { + constructor(value : CollatorMaxVariable | string); + + get value() : string; + + get ffiValue() : number; + + static Auto : CollatorMaxVariable; + + static Space : CollatorMaxVariable; + + static Punctuation : CollatorMaxVariable; + + static Symbol : CollatorMaxVariable; + + static Currency : CollatorMaxVariable; + + + -/** - - * See the {@link https://docs.rs/icu/latest/icu/collator/enum.MaxVariable.html Rust documentation for `MaxVariable`} for more information. - */ -export enum CollatorMaxVariable { - /** - */ - Auto = 'Auto', - /** - */ - Space = 'Space', - /** - */ - Punctuation = 'Punctuation', - /** - */ - Symbol = 'Symbol', - /** - */ - Currency = 'Currency', } \ No newline at end of file diff --git a/ffi/capi/bindings/js/CollatorMaxVariable.mjs b/ffi/capi/bindings/js/CollatorMaxVariable.mjs index a4e03bf83d7..e4bb1c0393c 100644 --- a/ffi/capi/bindings/js/CollatorMaxVariable.mjs +++ b/ffi/capi/bindings/js/CollatorMaxVariable.mjs @@ -1,26 +1,53 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" - -export const CollatorMaxVariable_js_to_rust = { - "Auto": 0, - "Space": 1, - "Punctuation": 2, - "Symbol": 3, - "Currency": 4, -}; - -export const CollatorMaxVariable_rust_to_js = { - [0]: "Auto", - [1]: "Space", - [2]: "Punctuation", - [3]: "Symbol", - [4]: "Currency", -}; - -export const CollatorMaxVariable = { - "Auto": "Auto", - "Space": "Space", - "Punctuation": "Punctuation", - "Symbol": "Symbol", - "Currency": "Currency", -}; +// generated by diplomat-tool +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; + +// Base enumerator definition +/** See the [Rust documentation for `MaxVariable`](https://docs.rs/icu/latest/icu/collator/enum.MaxVariable.html) for more information. +*/ +export class CollatorMaxVariable { + #value = undefined; + + static values = new Map([ + ["Auto", 0], + ["Space", 1], + ["Punctuation", 2], + ["Symbol", 3], + ["Currency", 4] + ]); + constructor(value) { + if (value instanceof CollatorMaxVariable) { + this.#value = value.value; + return; + } + + if (CollatorMaxVariable.values.has(value)) { + this.#value = value; + return; + } + + throw TypeError(value + " is not a CollatorMaxVariable and does not correspond to any of its enumerator values."); + } + + get value() { + return this.#value; + } + + get ffiValue() { + return CollatorMaxVariable.values.get(this.#value); + } + + static Auto = new CollatorMaxVariable("Auto"); + + static Space = new CollatorMaxVariable("Space"); + + static Punctuation = new CollatorMaxVariable("Punctuation"); + + static Symbol = new CollatorMaxVariable("Symbol"); + + static Currency = new CollatorMaxVariable("Currency"); + + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/CollatorNumeric.d.ts b/ffi/capi/bindings/js/CollatorNumeric.d.ts index 08a26e4cdcf..92f901acb66 100644 --- a/ffi/capi/bindings/js/CollatorNumeric.d.ts +++ b/ffi/capi/bindings/js/CollatorNumeric.d.ts @@ -1,16 +1,23 @@ +// generated by diplomat-tool +import type { pointer, char } from "./diplomat-runtime.d.ts"; + +// Base enumerator definition +/** See the [Rust documentation for `Numeric`](https://docs.rs/icu/latest/icu/collator/enum.Numeric.html) for more information. +*/ +export class CollatorNumeric { + constructor(value : CollatorNumeric | string); + + get value() : string; + + get ffiValue() : number; + + static Auto : CollatorNumeric; + + static Off : CollatorNumeric; + + static On : CollatorNumeric; + + + -/** - - * See the {@link https://docs.rs/icu/latest/icu/collator/enum.Numeric.html Rust documentation for `Numeric`} for more information. - */ -export enum CollatorNumeric { - /** - */ - Auto = 'Auto', - /** - */ - Off = 'Off', - /** - */ - On = 'On', } \ No newline at end of file diff --git a/ffi/capi/bindings/js/CollatorNumeric.mjs b/ffi/capi/bindings/js/CollatorNumeric.mjs index c9b9492e49e..01aa60a4da8 100644 --- a/ffi/capi/bindings/js/CollatorNumeric.mjs +++ b/ffi/capi/bindings/js/CollatorNumeric.mjs @@ -1,20 +1,47 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" - -export const CollatorNumeric_js_to_rust = { - "Auto": 0, - "Off": 1, - "On": 2, -}; - -export const CollatorNumeric_rust_to_js = { - [0]: "Auto", - [1]: "Off", - [2]: "On", -}; - -export const CollatorNumeric = { - "Auto": "Auto", - "Off": "Off", - "On": "On", -}; +// generated by diplomat-tool +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; + +// Base enumerator definition +/** See the [Rust documentation for `Numeric`](https://docs.rs/icu/latest/icu/collator/enum.Numeric.html) for more information. +*/ +export class CollatorNumeric { + #value = undefined; + + static values = new Map([ + ["Auto", 0], + ["Off", 1], + ["On", 2] + ]); + constructor(value) { + if (value instanceof CollatorNumeric) { + this.#value = value.value; + return; + } + + if (CollatorNumeric.values.has(value)) { + this.#value = value; + return; + } + + throw TypeError(value + " is not a CollatorNumeric and does not correspond to any of its enumerator values."); + } + + get value() { + return this.#value; + } + + get ffiValue() { + return CollatorNumeric.values.get(this.#value); + } + + static Auto = new CollatorNumeric("Auto"); + + static Off = new CollatorNumeric("Off"); + + static On = new CollatorNumeric("On"); + + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/CollatorOptions.d.ts b/ffi/capi/bindings/js/CollatorOptions.d.ts new file mode 100644 index 00000000000..e230e6df174 --- /dev/null +++ b/ffi/capi/bindings/js/CollatorOptions.d.ts @@ -0,0 +1,32 @@ +// generated by diplomat-tool +import type { CollatorAlternateHandling } from "./CollatorAlternateHandling" +import type { CollatorBackwardSecondLevel } from "./CollatorBackwardSecondLevel" +import type { CollatorCaseFirst } from "./CollatorCaseFirst" +import type { CollatorCaseLevel } from "./CollatorCaseLevel" +import type { CollatorMaxVariable } from "./CollatorMaxVariable" +import type { CollatorNumeric } from "./CollatorNumeric" +import type { CollatorStrength } from "./CollatorStrength" +import type { pointer, char } from "./diplomat-runtime.d.ts"; + + +/** See the [Rust documentation for `CollatorOptions`](https://docs.rs/icu/latest/icu/collator/struct.CollatorOptions.html) for more information. +*/ +export class CollatorOptions { + get strength() : CollatorStrength; + set strength(value: CollatorStrength); + get alternateHandling() : CollatorAlternateHandling; + set alternateHandling(value: CollatorAlternateHandling); + get caseFirst() : CollatorCaseFirst; + set caseFirst(value: CollatorCaseFirst); + get maxVariable() : CollatorMaxVariable; + set maxVariable(value: CollatorMaxVariable); + get caseLevel() : CollatorCaseLevel; + set caseLevel(value: CollatorCaseLevel); + get numeric() : CollatorNumeric; + set numeric(value: CollatorNumeric); + get backwardSecondLevel() : CollatorBackwardSecondLevel; + set backwardSecondLevel(value: CollatorBackwardSecondLevel); + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/CollatorOptions.mjs b/ffi/capi/bindings/js/CollatorOptions.mjs new file mode 100644 index 00000000000..cef22f71dd2 --- /dev/null +++ b/ffi/capi/bindings/js/CollatorOptions.mjs @@ -0,0 +1,101 @@ +// generated by diplomat-tool +import { CollatorAlternateHandling } from "./CollatorAlternateHandling.mjs" +import { CollatorBackwardSecondLevel } from "./CollatorBackwardSecondLevel.mjs" +import { CollatorCaseFirst } from "./CollatorCaseFirst.mjs" +import { CollatorCaseLevel } from "./CollatorCaseLevel.mjs" +import { CollatorMaxVariable } from "./CollatorMaxVariable.mjs" +import { CollatorNumeric } from "./CollatorNumeric.mjs" +import { CollatorStrength } from "./CollatorStrength.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; + + +/** See the [Rust documentation for `CollatorOptions`](https://docs.rs/icu/latest/icu/collator/struct.CollatorOptions.html) for more information. +*/ +export class CollatorOptions { + #strength; + get strength() { + return this.#strength; + } + set strength(value) { + this.#strength = value; + } + #alternateHandling; + get alternateHandling() { + return this.#alternateHandling; + } + set alternateHandling(value) { + this.#alternateHandling = value; + } + #caseFirst; + get caseFirst() { + return this.#caseFirst; + } + set caseFirst(value) { + this.#caseFirst = value; + } + #maxVariable; + get maxVariable() { + return this.#maxVariable; + } + set maxVariable(value) { + this.#maxVariable = value; + } + #caseLevel; + get caseLevel() { + return this.#caseLevel; + } + set caseLevel(value) { + this.#caseLevel = value; + } + #numeric; + get numeric() { + return this.#numeric; + } + set numeric(value) { + this.#numeric = value; + } + #backwardSecondLevel; + get backwardSecondLevel() { + return this.#backwardSecondLevel; + } + set backwardSecondLevel(value) { + this.#backwardSecondLevel = value; + } + + // Return this struct in FFI function friendly format. + // Returns an array that can be expanded with spread syntax (...) + + _intoFFI( + slice_cleanup_callbacks, + appendArrayMap + ) { + return [this.#strength.ffiValue, this.#alternateHandling.ffiValue, this.#caseFirst.ffiValue, this.#maxVariable.ffiValue, this.#caseLevel.ffiValue, this.#numeric.ffiValue, this.#backwardSecondLevel.ffiValue] + } + + // 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. + _fromFFI(ptr) { + const strengthDeref = diplomatRuntime.enumDiscriminant(wasm, ptr); + this.#strength = CollatorStrength[Array.from(CollatorStrength.values.keys())[strengthDeref]]; + const alternateHandlingDeref = diplomatRuntime.enumDiscriminant(wasm, ptr + 4); + this.#alternateHandling = CollatorAlternateHandling[Array.from(CollatorAlternateHandling.values.keys())[alternateHandlingDeref]]; + const caseFirstDeref = diplomatRuntime.enumDiscriminant(wasm, ptr + 8); + this.#caseFirst = CollatorCaseFirst[Array.from(CollatorCaseFirst.values.keys())[caseFirstDeref]]; + const maxVariableDeref = diplomatRuntime.enumDiscriminant(wasm, ptr + 12); + this.#maxVariable = CollatorMaxVariable[Array.from(CollatorMaxVariable.values.keys())[maxVariableDeref]]; + const caseLevelDeref = diplomatRuntime.enumDiscriminant(wasm, ptr + 16); + this.#caseLevel = CollatorCaseLevel[Array.from(CollatorCaseLevel.values.keys())[caseLevelDeref]]; + const numericDeref = diplomatRuntime.enumDiscriminant(wasm, ptr + 20); + this.#numeric = CollatorNumeric[Array.from(CollatorNumeric.values.keys())[numericDeref]]; + const backwardSecondLevelDeref = diplomatRuntime.enumDiscriminant(wasm, ptr + 24); + this.#backwardSecondLevel = CollatorBackwardSecondLevel[Array.from(CollatorBackwardSecondLevel.values.keys())[backwardSecondLevelDeref]]; + + return this; + } + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/CollatorOptionsV1.d.ts b/ffi/capi/bindings/js/CollatorOptionsV1.d.ts deleted file mode 100644 index f29ee443b80..00000000000 --- a/ffi/capi/bindings/js/CollatorOptionsV1.d.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { CollatorAlternateHandling } from "./CollatorAlternateHandling"; -import { CollatorBackwardSecondLevel } from "./CollatorBackwardSecondLevel"; -import { CollatorCaseFirst } from "./CollatorCaseFirst"; -import { CollatorCaseLevel } from "./CollatorCaseLevel"; -import { CollatorMaxVariable } from "./CollatorMaxVariable"; -import { CollatorNumeric } from "./CollatorNumeric"; -import { CollatorStrength } from "./CollatorStrength"; - -/** - - * See the {@link https://docs.rs/icu/latest/icu/collator/struct.CollatorOptions.html Rust documentation for `CollatorOptions`} for more information. - */ -export class CollatorOptionsV1 { - strength: CollatorStrength; - alternate_handling: CollatorAlternateHandling; - case_first: CollatorCaseFirst; - max_variable: CollatorMaxVariable; - case_level: CollatorCaseLevel; - numeric: CollatorNumeric; - backward_second_level: CollatorBackwardSecondLevel; -} diff --git a/ffi/capi/bindings/js/CollatorOptionsV1.mjs b/ffi/capi/bindings/js/CollatorOptionsV1.mjs deleted file mode 100644 index 5daa3937ac8..00000000000 --- a/ffi/capi/bindings/js/CollatorOptionsV1.mjs +++ /dev/null @@ -1,21 +0,0 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" -import { CollatorAlternateHandling_js_to_rust, CollatorAlternateHandling_rust_to_js } from "./CollatorAlternateHandling.mjs" -import { CollatorBackwardSecondLevel_js_to_rust, CollatorBackwardSecondLevel_rust_to_js } from "./CollatorBackwardSecondLevel.mjs" -import { CollatorCaseFirst_js_to_rust, CollatorCaseFirst_rust_to_js } from "./CollatorCaseFirst.mjs" -import { CollatorCaseLevel_js_to_rust, CollatorCaseLevel_rust_to_js } from "./CollatorCaseLevel.mjs" -import { CollatorMaxVariable_js_to_rust, CollatorMaxVariable_rust_to_js } from "./CollatorMaxVariable.mjs" -import { CollatorNumeric_js_to_rust, CollatorNumeric_rust_to_js } from "./CollatorNumeric.mjs" -import { CollatorStrength_js_to_rust, CollatorStrength_rust_to_js } from "./CollatorStrength.mjs" - -export class CollatorOptionsV1 { - constructor(underlying) { - this.strength = CollatorStrength_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, underlying)]; - this.alternate_handling = CollatorAlternateHandling_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, underlying + 4)]; - this.case_first = CollatorCaseFirst_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, underlying + 8)]; - this.max_variable = CollatorMaxVariable_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, underlying + 12)]; - this.case_level = CollatorCaseLevel_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, underlying + 16)]; - this.numeric = CollatorNumeric_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, underlying + 20)]; - this.backward_second_level = CollatorBackwardSecondLevel_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, underlying + 24)]; - } -} diff --git a/ffi/capi/bindings/js/CollatorResolvedOptionsV1.d.ts b/ffi/capi/bindings/js/CollatorResolvedOptionsV1.d.ts deleted file mode 100644 index 88c873f0269..00000000000 --- a/ffi/capi/bindings/js/CollatorResolvedOptionsV1.d.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { CollatorAlternateHandling } from "./CollatorAlternateHandling"; -import { CollatorBackwardSecondLevel } from "./CollatorBackwardSecondLevel"; -import { CollatorCaseFirst } from "./CollatorCaseFirst"; -import { CollatorCaseLevel } from "./CollatorCaseLevel"; -import { CollatorMaxVariable } from "./CollatorMaxVariable"; -import { CollatorNumeric } from "./CollatorNumeric"; -import { CollatorStrength } from "./CollatorStrength"; - -/** - - * See the {@link https://docs.rs/icu/latest/icu/collator/struct.ResolvedCollatorOptions.html Rust documentation for `ResolvedCollatorOptions`} for more information. - */ -export class CollatorResolvedOptionsV1 { - strength: CollatorStrength; - alternate_handling: CollatorAlternateHandling; - case_first: CollatorCaseFirst; - max_variable: CollatorMaxVariable; - case_level: CollatorCaseLevel; - numeric: CollatorNumeric; - backward_second_level: CollatorBackwardSecondLevel; -} diff --git a/ffi/capi/bindings/js/CollatorResolvedOptionsV1.mjs b/ffi/capi/bindings/js/CollatorResolvedOptionsV1.mjs deleted file mode 100644 index d13de53a5b6..00000000000 --- a/ffi/capi/bindings/js/CollatorResolvedOptionsV1.mjs +++ /dev/null @@ -1,21 +0,0 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" -import { CollatorAlternateHandling_js_to_rust, CollatorAlternateHandling_rust_to_js } from "./CollatorAlternateHandling.mjs" -import { CollatorBackwardSecondLevel_js_to_rust, CollatorBackwardSecondLevel_rust_to_js } from "./CollatorBackwardSecondLevel.mjs" -import { CollatorCaseFirst_js_to_rust, CollatorCaseFirst_rust_to_js } from "./CollatorCaseFirst.mjs" -import { CollatorCaseLevel_js_to_rust, CollatorCaseLevel_rust_to_js } from "./CollatorCaseLevel.mjs" -import { CollatorMaxVariable_js_to_rust, CollatorMaxVariable_rust_to_js } from "./CollatorMaxVariable.mjs" -import { CollatorNumeric_js_to_rust, CollatorNumeric_rust_to_js } from "./CollatorNumeric.mjs" -import { CollatorStrength_js_to_rust, CollatorStrength_rust_to_js } from "./CollatorStrength.mjs" - -export class CollatorResolvedOptionsV1 { - constructor(underlying) { - this.strength = CollatorStrength_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, underlying)]; - this.alternate_handling = CollatorAlternateHandling_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, underlying + 4)]; - this.case_first = CollatorCaseFirst_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, underlying + 8)]; - this.max_variable = CollatorMaxVariable_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, underlying + 12)]; - this.case_level = CollatorCaseLevel_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, underlying + 16)]; - this.numeric = CollatorNumeric_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, underlying + 20)]; - this.backward_second_level = CollatorBackwardSecondLevel_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, underlying + 24)]; - } -} diff --git a/ffi/capi/bindings/js/CollatorStrength.d.ts b/ffi/capi/bindings/js/CollatorStrength.d.ts index b3b867523f5..b7e7fb6a123 100644 --- a/ffi/capi/bindings/js/CollatorStrength.d.ts +++ b/ffi/capi/bindings/js/CollatorStrength.d.ts @@ -1,25 +1,29 @@ +// generated by diplomat-tool +import type { pointer, char } from "./diplomat-runtime.d.ts"; + +// Base enumerator definition +/** See the [Rust documentation for `Strength`](https://docs.rs/icu/latest/icu/collator/enum.Strength.html) for more information. +*/ +export class CollatorStrength { + constructor(value : CollatorStrength | string); + + get value() : string; + + get ffiValue() : number; + + static Auto : CollatorStrength; + + static Primary : CollatorStrength; + + static Secondary : CollatorStrength; + + static Tertiary : CollatorStrength; + + static Quaternary : CollatorStrength; + + static Identical : CollatorStrength; + + + -/** - - * See the {@link https://docs.rs/icu/latest/icu/collator/enum.Strength.html Rust documentation for `Strength`} for more information. - */ -export enum CollatorStrength { - /** - */ - Auto = 'Auto', - /** - */ - Primary = 'Primary', - /** - */ - Secondary = 'Secondary', - /** - */ - Tertiary = 'Tertiary', - /** - */ - Quaternary = 'Quaternary', - /** - */ - Identical = 'Identical', } \ No newline at end of file diff --git a/ffi/capi/bindings/js/CollatorStrength.mjs b/ffi/capi/bindings/js/CollatorStrength.mjs index 2c529d7c914..796b732766c 100644 --- a/ffi/capi/bindings/js/CollatorStrength.mjs +++ b/ffi/capi/bindings/js/CollatorStrength.mjs @@ -1,29 +1,56 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" - -export const CollatorStrength_js_to_rust = { - "Auto": 0, - "Primary": 1, - "Secondary": 2, - "Tertiary": 3, - "Quaternary": 4, - "Identical": 5, -}; - -export const CollatorStrength_rust_to_js = { - [0]: "Auto", - [1]: "Primary", - [2]: "Secondary", - [3]: "Tertiary", - [4]: "Quaternary", - [5]: "Identical", -}; - -export const CollatorStrength = { - "Auto": "Auto", - "Primary": "Primary", - "Secondary": "Secondary", - "Tertiary": "Tertiary", - "Quaternary": "Quaternary", - "Identical": "Identical", -}; +// generated by diplomat-tool +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; + +// Base enumerator definition +/** See the [Rust documentation for `Strength`](https://docs.rs/icu/latest/icu/collator/enum.Strength.html) for more information. +*/ +export class CollatorStrength { + #value = undefined; + + static values = new Map([ + ["Auto", 0], + ["Primary", 1], + ["Secondary", 2], + ["Tertiary", 3], + ["Quaternary", 4], + ["Identical", 5] + ]); + constructor(value) { + if (value instanceof CollatorStrength) { + this.#value = value.value; + return; + } + + if (CollatorStrength.values.has(value)) { + this.#value = value; + return; + } + + throw TypeError(value + " is not a CollatorStrength and does not correspond to any of its enumerator values."); + } + + get value() { + return this.#value; + } + + get ffiValue() { + return CollatorStrength.values.get(this.#value); + } + + static Auto = new CollatorStrength("Auto"); + + static Primary = new CollatorStrength("Primary"); + + static Secondary = new CollatorStrength("Secondary"); + + static Tertiary = new CollatorStrength("Tertiary"); + + static Quaternary = new CollatorStrength("Quaternary"); + + static Identical = new CollatorStrength("Identical"); + + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/ComposingNormalizer.d.ts b/ffi/capi/bindings/js/ComposingNormalizer.d.ts index e0cc8bd566b..b3315961dcd 100644 --- a/ffi/capi/bindings/js/ComposingNormalizer.d.ts +++ b/ffi/capi/bindings/js/ComposingNormalizer.d.ts @@ -1,75 +1,30 @@ -import { usize } from "./diplomat-runtime" -import { FFIError } from "./diplomat-runtime" -import { DataError } from "./DataError"; -import { DataProvider } from "./DataProvider"; +// generated by diplomat-tool +import type { DataProvider } from "./DataProvider" +import type { pointer, char } from "./diplomat-runtime.d.ts"; -/** - * See the {@link https://docs.rs/icu/latest/icu/normalizer/struct.ComposingNormalizer.html Rust documentation for `ComposingNormalizer`} for more information. - */ +/** See the [Rust documentation for `ComposingNormalizer`](https://docs.rs/icu/latest/icu/normalizer/struct.ComposingNormalizer.html) for more information. +*/ export class ComposingNormalizer { + - /** + get ffiValue(): pointer; - * Construct a new ComposingNormalizer instance for NFC - * See the {@link https://docs.rs/icu/latest/icu/normalizer/struct.ComposingNormalizer.html#method.new_nfc Rust documentation for `new_nfc`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static create_nfc(provider: DataProvider): ComposingNormalizer | never; + static createNfc(provider: DataProvider): ComposingNormalizer; - /** + static createNfkc(provider: DataProvider): ComposingNormalizer; - * Construct a new ComposingNormalizer instance for NFKC + normalize(s: string): string; - * See the {@link https://docs.rs/icu/latest/icu/normalizer/struct.ComposingNormalizer.html#method.new_nfkc Rust documentation for `new_nfkc`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static create_nfkc(provider: DataProvider): ComposingNormalizer | never; + isNormalized(s: string): boolean; - /** + isNormalizedUtf16(s: string): boolean; - * Normalize a string + isNormalizedUpTo(s: string): number; - * Ill-formed input is treated as if errors had been replaced with REPLACEMENT CHARACTERs according to the WHATWG Encoding Standard. + isNormalizedUtf16UpTo(s: string): number; - * See the {@link https://docs.rs/icu/latest/icu/normalizer/struct.ComposingNormalizer.html#method.normalize_utf8 Rust documentation for `normalize_utf8`} for more information. - */ - normalize(s: string): string; + - /** - - * Check if a string is normalized - - * Ill-formed input is treated as if errors had been replaced with REPLACEMENT CHARACTERs according to the WHATWG Encoding Standard. - - * See the {@link https://docs.rs/icu/latest/icu/normalizer/struct.ComposingNormalizer.html#method.is_normalized_utf8 Rust documentation for `is_normalized_utf8`} for more information. - */ - is_normalized(s: string): boolean; - - /** - - * Check if a string is normalized - - * Ill-formed input is treated as if errors had been replaced with REPLACEMENT CHARACTERs according to the WHATWG Encoding Standard. - - * See the {@link https://docs.rs/icu/latest/icu/normalizer/struct.ComposingNormalizer.html#method.is_normalized_utf16 Rust documentation for `is_normalized_utf16`} for more information. - */ - is_normalized_utf16(s: string): boolean; - - /** - - * Return the index a slice of potentially-invalid UTF-8 is normalized up to - - * See the {@link https://docs.rs/icu/latest/icu/normalizer/struct.ComposingNormalizer.html#method.is_normalized_utf8_up_to Rust documentation for `is_normalized_utf8_up_to`} for more information. - */ - is_normalized_up_to(s: string): usize; - - /** - - * Return the index a slice of potentially-invalid UTF-8 is normalized up to - - * See the {@link https://docs.rs/icu/latest/icu/normalizer/struct.ComposingNormalizer.html#method.is_normalized_utf16_up_to Rust documentation for `is_normalized_utf16_up_to`} for more information. - */ - is_normalized_utf16_up_to(s: string): usize; -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/ComposingNormalizer.mjs b/ffi/capi/bindings/js/ComposingNormalizer.mjs index eddc562f538..1be6c7af8f6 100644 --- a/ffi/capi/bindings/js/ComposingNormalizer.mjs +++ b/ffi/capi/bindings/js/ComposingNormalizer.mjs @@ -1,89 +1,155 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" -import { DataError_js_to_rust, DataError_rust_to_js } from "./DataError.mjs" +// generated by diplomat-tool +import { DataError } from "./DataError.mjs" +import { DataProvider } from "./DataProvider.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -const ComposingNormalizer_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XComposingNormalizer_destroy(underlying); -}); +/** See the [Rust documentation for `ComposingNormalizer`](https://docs.rs/icu/latest/icu/normalizer/struct.ComposingNormalizer.html) for more information. +*/ + +const ComposingNormalizer_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XComposingNormalizer_destroy(ptr); +}); export class ComposingNormalizer { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - ComposingNormalizer_box_destroy_registry.register(this, underlying); + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + + constructor(ptr, selfEdge) { + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + ComposingNormalizer_box_destroy_registry.register(this, this.#ptr); + } + + get ffiValue() { + return this.#ptr; + } + + + static createNfc(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XComposingNormalizer_create_nfc(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new ComposingNormalizer(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static createNfkc(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XComposingNormalizer_create_nfkc(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new ComposingNormalizer(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } } - } - static create_nfc(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XComposingNormalizer_create_nfc(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new ComposingNormalizer(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } + normalize(s) { + + const sSlice = diplomatRuntime.DiplomatBuf.str8(wasm, s); + + const write = wasm.diplomat_buffer_write_create(0); + wasm.ICU4XComposingNormalizer_normalize(this.ffiValue, sSlice.ptr, sSlice.size, write); + + try { + + return diplomatRuntime.readString8(wasm, wasm.diplomat_buffer_write_get_bytes(write), wasm.diplomat_buffer_write_len(write)); + } finally { + + sSlice.free(); + + wasm.diplomat_buffer_write_destroy(write); + + } + } - static create_nfkc(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XComposingNormalizer_create_nfkc(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new ComposingNormalizer(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } + isNormalized(s) { + + const sSlice = diplomatRuntime.DiplomatBuf.str8(wasm, s); + const result = wasm.ICU4XComposingNormalizer_is_normalized(this.ffiValue, sSlice.ptr, sSlice.size); + + try { + + return result; + } finally { + + sSlice.free(); + + } + } - normalize(arg_s) { - const buf_arg_s = diplomatRuntime.DiplomatBuf.str8(wasm, arg_s); - const diplomat_out = diplomatRuntime.withDiplomatWrite(wasm, (write) => { - return wasm.ICU4XComposingNormalizer_normalize(this.underlying, buf_arg_s.ptr, buf_arg_s.size, write); - }); - buf_arg_s.free(); - return diplomat_out; - } + isNormalizedUtf16(s) { + + const sSlice = diplomatRuntime.DiplomatBuf.str16(wasm, s); + const result = wasm.ICU4XComposingNormalizer_is_normalized_utf16(this.ffiValue, sSlice.ptr, sSlice.size); + + try { + + return result; + } finally { + + sSlice.free(); + + } + } - is_normalized(arg_s) { - const buf_arg_s = diplomatRuntime.DiplomatBuf.str8(wasm, arg_s); - const diplomat_out = wasm.ICU4XComposingNormalizer_is_normalized(this.underlying, buf_arg_s.ptr, buf_arg_s.size); - buf_arg_s.free(); - return diplomat_out; - } + isNormalizedUpTo(s) { + + const sSlice = diplomatRuntime.DiplomatBuf.str8(wasm, s); + const result = wasm.ICU4XComposingNormalizer_is_normalized_up_to(this.ffiValue, sSlice.ptr, sSlice.size); + + try { + + return result; + } finally { + + sSlice.free(); + + } + } - is_normalized_utf16(arg_s) { - const buf_arg_s = diplomatRuntime.DiplomatBuf.str16(wasm, arg_s); - const diplomat_out = wasm.ICU4XComposingNormalizer_is_normalized_utf16(this.underlying, buf_arg_s.ptr, buf_arg_s.size); - buf_arg_s.free(); - return diplomat_out; - } + isNormalizedUtf16UpTo(s) { + + const sSlice = diplomatRuntime.DiplomatBuf.str16(wasm, s); + const result = wasm.ICU4XComposingNormalizer_is_normalized_utf16_up_to(this.ffiValue, sSlice.ptr, sSlice.size); + + try { + + return result; + } finally { + + sSlice.free(); + + } + } - is_normalized_up_to(arg_s) { - const buf_arg_s = diplomatRuntime.DiplomatBuf.str8(wasm, arg_s); - const diplomat_out = wasm.ICU4XComposingNormalizer_is_normalized_up_to(this.underlying, buf_arg_s.ptr, buf_arg_s.size); - buf_arg_s.free(); - return diplomat_out; - } + - is_normalized_utf16_up_to(arg_s) { - const buf_arg_s = diplomatRuntime.DiplomatBuf.str16(wasm, arg_s); - const diplomat_out = wasm.ICU4XComposingNormalizer_is_normalized_utf16_up_to(this.underlying, buf_arg_s.ptr, buf_arg_s.size); - buf_arg_s.free(); - return diplomat_out; - } -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/CustomTimeZone.d.ts b/ffi/capi/bindings/js/CustomTimeZone.d.ts index 61f3c3a35eb..efd247b72ff 100644 --- a/ffi/capi/bindings/js/CustomTimeZone.d.ts +++ b/ffi/capi/bindings/js/CustomTimeZone.d.ts @@ -1,305 +1,74 @@ -import { i8, i32 } from "./diplomat-runtime" -import { FFIError } from "./diplomat-runtime" -import { IsoDateTime } from "./IsoDateTime"; -import { MetazoneCalculator } from "./MetazoneCalculator"; -import { TimeZoneIdMapper } from "./TimeZoneIdMapper"; -import { TimeZoneInvalidIdError } from "./TimeZoneInvalidIdError"; -import { TimeZoneInvalidOffsetError } from "./TimeZoneInvalidOffsetError"; - -/** - - * See the {@link https://docs.rs/icu/latest/icu/timezone/struct.CustomTimeZone.html Rust documentation for `CustomTimeZone`} for more information. - */ -export class CustomTimeZone { - - /** - - * Creates a time zone from an offset string. - - * See the {@link https://docs.rs/icu/latest/icu/timezone/struct.CustomTimeZone.html#method.try_from_str Rust documentation for `try_from_str`} for more information. - * @throws {@link FFIError}<{@link TimeZoneInvalidOffsetError}> - */ - static create_from_string(s: string): CustomTimeZone | never; - - /** - - * Creates a time zone with no information. - - * See the {@link https://docs.rs/icu/latest/icu/timezone/struct.CustomTimeZone.html#method.new_empty Rust documentation for `new_empty`} for more information. - */ - static create_empty(): CustomTimeZone; - - /** - - * Creates a time zone for UTC (Coordinated Universal Time). - - * See the {@link https://docs.rs/icu/latest/icu/timezone/struct.CustomTimeZone.html#method.utc Rust documentation for `utc`} for more information. - */ - static create_utc(): CustomTimeZone; - - /** - - * Creates a time zone for GMT (London winter time). - - * See the {@link https://docs.rs/icu/latest/icu/timezone/struct.CustomTimeZone.html#method.gmt Rust documentation for `gmt`} for more information. - */ - static create_gmt(): CustomTimeZone; - - /** - - * Creates a time zone for BST (London summer time). - - * See the {@link https://docs.rs/icu/latest/icu/timezone/struct.CustomTimeZone.html#method.bst Rust documentation for `bst`} for more information. - */ - static create_bst(): CustomTimeZone; - - /** - - * Sets the `gmt_offset` field from offset seconds. - - * Errors if the offset seconds are out of range. - - * See the {@link https://docs.rs/icu/latest/icu/timezone/struct.GmtOffset.html#method.try_from_offset_seconds Rust documentation for `try_from_offset_seconds`} for more information. - - * Additional information: {@link https://docs.rs/icu/latest/icu/timezone/struct.GmtOffset.html 1} - * @throws {@link FFIError}<{@link TimeZoneInvalidOffsetError}> - */ - try_set_gmt_offset_seconds(offset_seconds: i32): void | never; - - /** - - * Sets the `gmt_offset` field from offset eighths of an hour. - - * See the {@link https://docs.rs/icu/latest/icu/timezone/struct.GmtOffset.html#method.from_offset_eighths_of_hour Rust documentation for `from_offset_eighths_of_hour`} for more information. - */ - set_gmt_offset_eighths_of_hour(offset_eighths_of_hour: i8): void; - - /** - - * Clears the `gmt_offset` field. - - * See the {@link https://docs.rs/icu/latest/icu/timezone/struct.GmtOffset.html#method.offset_seconds Rust documentation for `offset_seconds`} for more information. - - * Additional information: {@link https://docs.rs/icu/latest/icu/timezone/struct.GmtOffset.html 1} - */ - clear_gmt_offset(): void; - - /** - - * Returns the value of the `gmt_offset` field as offset seconds. - - * Returns null if the `gmt_offset` field is empty. - - * See the {@link https://docs.rs/icu/latest/icu/timezone/struct.GmtOffset.html#method.offset_seconds Rust documentation for `offset_seconds`} for more information. - - * Additional information: {@link https://docs.rs/icu/latest/icu/timezone/struct.GmtOffset.html 1} - */ - gmt_offset_seconds(): i32 | undefined; - - /** - - * Returns whether the `gmt_offset` field is positive. - - * Returns null if the `gmt_offset` field is empty. - - * See the {@link https://docs.rs/icu/latest/icu/timezone/struct.GmtOffset.html#method.is_positive Rust documentation for `is_positive`} for more information. - */ - is_gmt_offset_positive(): boolean | undefined; - - /** - - * Returns whether the `gmt_offset` field is zero. - - * Returns null if the `gmt_offset` field is empty (which is not the same as zero). - - * See the {@link https://docs.rs/icu/latest/icu/timezone/struct.GmtOffset.html#method.is_zero Rust documentation for `is_zero`} for more information. - */ - is_gmt_offset_zero(): boolean | undefined; - - /** +// generated by diplomat-tool +import type { IsoDateTime } from "./IsoDateTime" +import type { MetazoneCalculator } from "./MetazoneCalculator" +import type { TimeZoneIdMapper } from "./TimeZoneIdMapper" +import type { pointer, char } from "./diplomat-runtime.d.ts"; - * Returns whether the `gmt_offset` field has nonzero minutes. - * Returns null if the `gmt_offset` field is empty. - - * See the {@link https://docs.rs/icu/latest/icu/timezone/struct.GmtOffset.html#method.has_minutes Rust documentation for `has_minutes`} for more information. - */ - gmt_offset_has_minutes(): boolean | undefined; - - /** - - * Returns whether the `gmt_offset` field has nonzero seconds. - - * Returns null if the `gmt_offset` field is empty. - - * See the {@link https://docs.rs/icu/latest/icu/timezone/struct.GmtOffset.html#method.has_seconds Rust documentation for `has_seconds`} for more information. - */ - gmt_offset_has_seconds(): boolean | undefined; - - /** - - * Sets the `time_zone_id` field from a BCP-47 string. - - * Errors if the string is not a valid BCP-47 time zone ID. - - * See the {@link https://docs.rs/icu/latest/icu/timezone/struct.CustomTimeZone.html#structfield.time_zone_id Rust documentation for `time_zone_id`} for more information. - - * Additional information: {@link https://docs.rs/icu/latest/icu/timezone/struct.TimeZoneBcp47Id.html 1} - * @throws {@link FFIError}<{@link TimeZoneInvalidIdError}> - */ - try_set_time_zone_id(id: string): void | never; - - /** - - * Sets the `time_zone_id` field from an IANA string by looking up the corresponding BCP-47 string. - - * Errors if the string is not a valid BCP-47 time zone ID. - * @throws {@link FFIError}<{@link TimeZoneInvalidIdError}> - */ - try_set_iana_time_zone_id(mapper: TimeZoneIdMapper, id: string): void | never; - - /** - - * Clears the `time_zone_id` field. - - * See the {@link https://docs.rs/icu/latest/icu/timezone/struct.CustomTimeZone.html#structfield.time_zone_id Rust documentation for `time_zone_id`} for more information. - - * Additional information: {@link https://docs.rs/icu/latest/icu/timezone/struct.TimeZoneBcp47Id.html 1} - */ - clear_time_zone_id(): void; - - /** - - * Writes the value of the `time_zone_id` field as a string. - - * Returns null if the `time_zone_id` field is empty. - - * See the {@link https://docs.rs/icu/latest/icu/timezone/struct.CustomTimeZone.html#structfield.time_zone_id Rust documentation for `time_zone_id`} for more information. - - * Additional information: {@link https://docs.rs/icu/latest/icu/timezone/struct.TimeZoneBcp47Id.html 1} - */ - time_zone_id(): string | undefined; - - /** - - * Sets the `metazone_id` field from a string. - - * Returns null if the string is not a valid BCP-47 metazone ID. - - * See the {@link https://docs.rs/icu/latest/icu/timezone/struct.CustomTimeZone.html#structfield.metazone_id Rust documentation for `metazone_id`} for more information. - - * Additional information: {@link https://docs.rs/icu/latest/icu/timezone/struct.MetazoneId.html 1} - * @throws {@link FFIError}<{@link TimeZoneInvalidIdError}> - */ - try_set_metazone_id(id: string): void | never; - - /** - - * Clears the `metazone_id` field. - - * See the {@link https://docs.rs/icu/latest/icu/timezone/struct.CustomTimeZone.html#structfield.metazone_id Rust documentation for `metazone_id`} for more information. - - * Additional information: {@link https://docs.rs/icu/latest/icu/timezone/struct.MetazoneId.html 1} - */ - clear_metazone_id(): void; - - /** - - * Writes the value of the `metazone_id` field as a string. - - * Returns null if the `metazone_id` field is empty. - - * See the {@link https://docs.rs/icu/latest/icu/timezone/struct.CustomTimeZone.html#structfield.metazone_id Rust documentation for `metazone_id`} for more information. - - * Additional information: {@link https://docs.rs/icu/latest/icu/timezone/struct.MetazoneId.html 1} - */ - metazone_id(): string | undefined; - - /** - - * Sets the `zone_variant` field from a string. - - * Returns null if the string is not a valid zone variant. - - * See the {@link https://docs.rs/icu/latest/icu/timezone/struct.CustomTimeZone.html#structfield.zone_variant Rust documentation for `zone_variant`} for more information. +/** See the [Rust documentation for `CustomTimeZone`](https://docs.rs/icu/latest/icu/timezone/struct.CustomTimeZone.html) for more information. +*/ +export class CustomTimeZone { + - * Additional information: {@link https://docs.rs/icu/latest/icu/timezone/struct.ZoneVariant.html 1} - */ - try_set_zone_variant(id: string): void | undefined; + get ffiValue(): pointer; - /** - * Clears the `zone_variant` field. + static createFromString(s: string): CustomTimeZone; - * See the {@link https://docs.rs/icu/latest/icu/timezone/struct.CustomTimeZone.html#structfield.zone_variant Rust documentation for `zone_variant`} for more information. + static createEmpty(): CustomTimeZone; - * Additional information: {@link https://docs.rs/icu/latest/icu/timezone/struct.ZoneVariant.html 1} - */ - clear_zone_variant(): void; + static createUtc(): CustomTimeZone; - /** + static createGmt(): CustomTimeZone; - * Writes the value of the `zone_variant` field as a string. + static createBst(): CustomTimeZone; - * Returns null if the `zone_variant` field is empty. + trySetGmtOffsetSeconds(offsetSeconds: number): void; - * See the {@link https://docs.rs/icu/latest/icu/timezone/struct.CustomTimeZone.html#structfield.zone_variant Rust documentation for `zone_variant`} for more information. + setGmtOffsetEighthsOfHour(offsetEighthsOfHour: number): void; - * Additional information: {@link https://docs.rs/icu/latest/icu/timezone/struct.ZoneVariant.html 1} - */ - zone_variant(): string | undefined; + clearGmtOffset(): void; - /** + get gmtOffsetSeconds(): number | null; - * Sets the `zone_variant` field to "standard" time, which may or may not correspond to a display name with "Standard" in its name. + get isGmtOffsetPositive(): boolean | null; - * See the {@link https://docs.rs/icu/latest/icu/timezone/struct.ZoneVariant.html#method.standard Rust documentation for `standard`} for more information. + get isGmtOffsetZero(): boolean | null; - * Additional information: {@link https://docs.rs/icu/latest/icu/timezone/struct.CustomTimeZone.html#structfield.zone_variant 1} - */ - set_standard_time(): void; + get gmtOffsetHasMinutes(): boolean | null; - /** + get gmtOffsetHasSeconds(): boolean | null; - * Sets the `zone_variant` field to "daylight" time, which may or may not correspond to a display name with "Daylight" in its name. + trySetTimeZoneId(id: string): void; - * See the {@link https://docs.rs/icu/latest/icu/timezone/struct.ZoneVariant.html#method.daylight Rust documentation for `daylight`} for more information. + trySetIanaTimeZoneId(mapper: TimeZoneIdMapper, id: string): void; - * Additional information: {@link https://docs.rs/icu/latest/icu/timezone/struct.CustomTimeZone.html#structfield.zone_variant 1} - */ - set_daylight_time(): void; + clearTimeZoneId(): void; - /** + get timeZoneId(): string | null; - * Returns whether the `zone_variant` field is standard time. + trySetMetazoneId(id: string): void; - * Returns null if the `zone_variant` field is empty. + clearMetazoneId(): void; - * See the {@link https://docs.rs/icu/latest/icu/timezone/struct.ZoneVariant.html#method.standard Rust documentation for `standard`} for more information. + get metazoneId(): string | null; - * Additional information: {@link https://docs.rs/icu/latest/icu/timezone/struct.CustomTimeZone.html#structfield.zone_variant 1} - */ - is_standard_time(): boolean | undefined; + trySetZoneVariant(id: string): boolean; - /** + clearZoneVariant(): void; - * Returns whether the `zone_variant` field is daylight time. + get zoneVariant(): string | null; - * Returns null if the `zone_variant` field is empty. + setStandardTime(): void; - * See the {@link https://docs.rs/icu/latest/icu/timezone/struct.ZoneVariant.html#method.daylight Rust documentation for `daylight`} for more information. + setDaylightTime(): void; - * Additional information: {@link https://docs.rs/icu/latest/icu/timezone/struct.CustomTimeZone.html#structfield.zone_variant 1} - */ - is_daylight_time(): boolean | undefined; + get isStandardTime(): boolean | null; - /** + get isDaylightTime(): boolean | null; - * Sets the metazone based on the time zone and the local timestamp. + maybeCalculateMetazone(metazoneCalculator: MetazoneCalculator, localDatetime: IsoDateTime): void; - * See the {@link https://docs.rs/icu/latest/icu/timezone/struct.CustomTimeZone.html#method.maybe_calculate_metazone Rust documentation for `maybe_calculate_metazone`} for more information. + - * Additional information: {@link https://docs.rs/icu/latest/icu/timezone/struct.MetazoneCalculator.html#method.compute_metazone_from_time_zone 1} - */ - maybe_calculate_metazone(metazone_calculator: MetazoneCalculator, local_datetime: IsoDateTime): void; -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/CustomTimeZone.mjs b/ffi/capi/bindings/js/CustomTimeZone.mjs index 422866bab6a..89d7c487cc8 100644 --- a/ffi/capi/bindings/js/CustomTimeZone.mjs +++ b/ffi/capi/bindings/js/CustomTimeZone.mjs @@ -1,306 +1,462 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" -import { TimeZoneInvalidIdError_js_to_rust, TimeZoneInvalidIdError_rust_to_js } from "./TimeZoneInvalidIdError.mjs" -import { TimeZoneInvalidOffsetError_js_to_rust, TimeZoneInvalidOffsetError_rust_to_js } from "./TimeZoneInvalidOffsetError.mjs" +// generated by diplomat-tool +import { IsoDateTime } from "./IsoDateTime.mjs" +import { MetazoneCalculator } from "./MetazoneCalculator.mjs" +import { TimeZoneIdMapper } from "./TimeZoneIdMapper.mjs" +import { TimeZoneInvalidIdError } from "./TimeZoneInvalidIdError.mjs" +import { TimeZoneInvalidOffsetError } from "./TimeZoneInvalidOffsetError.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -const CustomTimeZone_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XCustomTimeZone_destroy(underlying); -}); +/** See the [Rust documentation for `CustomTimeZone`](https://docs.rs/icu/latest/icu/timezone/struct.CustomTimeZone.html) for more information. +*/ + +const CustomTimeZone_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XCustomTimeZone_destroy(ptr); +}); export class CustomTimeZone { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - CustomTimeZone_box_destroy_registry.register(this, underlying); + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + + constructor(ptr, selfEdge) { + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + CustomTimeZone_box_destroy_registry.register(this, this.#ptr); + } + + get ffiValue() { + return this.#ptr; + } + + + static createFromString(s) { + + const sSlice = diplomatRuntime.DiplomatBuf.str8(wasm, s); + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCustomTimeZone_create_from_string(diplomat_receive_buffer, sSlice.ptr, sSlice.size); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = TimeZoneInvalidOffsetError[Array.from(TimeZoneInvalidOffsetError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('TimeZoneInvalidOffsetError: ' + cause.value, { cause }); + } + return new CustomTimeZone(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + sSlice.free(); + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static createEmpty() { + const result = wasm.ICU4XCustomTimeZone_create_empty(); + + try { + + return new CustomTimeZone(result, []); + } finally { + + } + } + + static createUtc() { + const result = wasm.ICU4XCustomTimeZone_create_utc(); + + try { + + return new CustomTimeZone(result, []); + } finally { + + } + } + + static createGmt() { + const result = wasm.ICU4XCustomTimeZone_create_gmt(); + + try { + + return new CustomTimeZone(result, []); + } finally { + + } + } + + static createBst() { + const result = wasm.ICU4XCustomTimeZone_create_bst(); + + try { + + return new CustomTimeZone(result, []); + } finally { + + } + } + + trySetGmtOffsetSeconds(offsetSeconds) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCustomTimeZone_try_set_gmt_offset_seconds(diplomat_receive_buffer, this.ffiValue, offsetSeconds); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = TimeZoneInvalidOffsetError[Array.from(TimeZoneInvalidOffsetError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('TimeZoneInvalidOffsetError: ' + cause.value, { cause }); + } + + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + setGmtOffsetEighthsOfHour(offsetEighthsOfHour) { + wasm.ICU4XCustomTimeZone_set_gmt_offset_eighths_of_hour(this.ffiValue, offsetEighthsOfHour); + + try { + + } finally { + + } + } + + clearGmtOffset() { + wasm.ICU4XCustomTimeZone_clear_gmt_offset(this.ffiValue); + + try { + + } finally { + + } + } + + get gmtOffsetSeconds() { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCustomTimeZone_gmt_offset_seconds(diplomat_receive_buffer, this.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + return null; + } + return (new Int32Array(wasm.memory.buffer, diplomat_receive_buffer, 1))[0]; + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + get isGmtOffsetPositive() { + + const diplomat_receive_buffer = wasm.diplomat_alloc(2, 1); + const result = wasm.ICU4XCustomTimeZone_is_gmt_offset_positive(diplomat_receive_buffer, this.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 1)) { + return null; + } + return (new Uint8Array(wasm.memory.buffer, diplomat_receive_buffer, 1))[0] == 1; + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 2, 1); + + } + } + + get isGmtOffsetZero() { + + const diplomat_receive_buffer = wasm.diplomat_alloc(2, 1); + const result = wasm.ICU4XCustomTimeZone_is_gmt_offset_zero(diplomat_receive_buffer, this.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 1)) { + return null; + } + return (new Uint8Array(wasm.memory.buffer, diplomat_receive_buffer, 1))[0] == 1; + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 2, 1); + + } + } + + get gmtOffsetHasMinutes() { + + const diplomat_receive_buffer = wasm.diplomat_alloc(2, 1); + const result = wasm.ICU4XCustomTimeZone_gmt_offset_has_minutes(diplomat_receive_buffer, this.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 1)) { + return null; + } + return (new Uint8Array(wasm.memory.buffer, diplomat_receive_buffer, 1))[0] == 1; + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 2, 1); + + } + } + + get gmtOffsetHasSeconds() { + + const diplomat_receive_buffer = wasm.diplomat_alloc(2, 1); + const result = wasm.ICU4XCustomTimeZone_gmt_offset_has_seconds(diplomat_receive_buffer, this.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 1)) { + return null; + } + return (new Uint8Array(wasm.memory.buffer, diplomat_receive_buffer, 1))[0] == 1; + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 2, 1); + + } } - } - - static create_from_string(arg_s) { - const buf_arg_s = diplomatRuntime.DiplomatBuf.str8(wasm, arg_s); - const diplomat_out = (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCustomTimeZone_create_from_string(diplomat_receive_buffer, buf_arg_s.ptr, buf_arg_s.size); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new CustomTimeZone(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = TimeZoneInvalidOffsetError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - buf_arg_s.free(); - return diplomat_out; - } - - static create_empty() { - return new CustomTimeZone(wasm.ICU4XCustomTimeZone_create_empty(), true, []); - } - - static create_utc() { - return new CustomTimeZone(wasm.ICU4XCustomTimeZone_create_utc(), true, []); - } - - static create_gmt() { - return new CustomTimeZone(wasm.ICU4XCustomTimeZone_create_gmt(), true, []); - } - - static create_bst() { - return new CustomTimeZone(wasm.ICU4XCustomTimeZone_create_bst(), true, []); - } - - try_set_gmt_offset_seconds(arg_offset_seconds) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCustomTimeZone_try_set_gmt_offset_seconds(diplomat_receive_buffer, this.underlying, arg_offset_seconds); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = {}; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = TimeZoneInvalidOffsetError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - set_gmt_offset_eighths_of_hour(arg_offset_eighths_of_hour) { - wasm.ICU4XCustomTimeZone_set_gmt_offset_eighths_of_hour(this.underlying, arg_offset_eighths_of_hour); - } - - clear_gmt_offset() { - wasm.ICU4XCustomTimeZone_clear_gmt_offset(this.underlying); - } - - gmt_offset_seconds() { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCustomTimeZone_gmt_offset_seconds(diplomat_receive_buffer, this.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (!is_ok) { - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return; - } - const value = (new Int32Array(wasm.memory.buffer, diplomat_receive_buffer, 1))[0]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return value; - })(); - } - - is_gmt_offset_positive() { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(2, 1); - wasm.ICU4XCustomTimeZone_is_gmt_offset_positive(diplomat_receive_buffer, this.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 1); - if (!is_ok) { - wasm.diplomat_free(diplomat_receive_buffer, 2, 1); - return; - } - const value = (new Uint8Array(wasm.memory.buffer, diplomat_receive_buffer, 1))[0] == 1; - wasm.diplomat_free(diplomat_receive_buffer, 2, 1); - return value; - })(); - } - - is_gmt_offset_zero() { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(2, 1); - wasm.ICU4XCustomTimeZone_is_gmt_offset_zero(diplomat_receive_buffer, this.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 1); - if (!is_ok) { - wasm.diplomat_free(diplomat_receive_buffer, 2, 1); - return; - } - const value = (new Uint8Array(wasm.memory.buffer, diplomat_receive_buffer, 1))[0] == 1; - wasm.diplomat_free(diplomat_receive_buffer, 2, 1); - return value; - })(); - } - - gmt_offset_has_minutes() { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(2, 1); - wasm.ICU4XCustomTimeZone_gmt_offset_has_minutes(diplomat_receive_buffer, this.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 1); - if (!is_ok) { - wasm.diplomat_free(diplomat_receive_buffer, 2, 1); - return; - } - const value = (new Uint8Array(wasm.memory.buffer, diplomat_receive_buffer, 1))[0] == 1; - wasm.diplomat_free(diplomat_receive_buffer, 2, 1); - return value; - })(); - } - - gmt_offset_has_seconds() { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(2, 1); - wasm.ICU4XCustomTimeZone_gmt_offset_has_seconds(diplomat_receive_buffer, this.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 1); - if (!is_ok) { - wasm.diplomat_free(diplomat_receive_buffer, 2, 1); - return; - } - const value = (new Uint8Array(wasm.memory.buffer, diplomat_receive_buffer, 1))[0] == 1; - wasm.diplomat_free(diplomat_receive_buffer, 2, 1); - return value; - })(); - } - - try_set_time_zone_id(arg_id) { - const buf_arg_id = diplomatRuntime.DiplomatBuf.str8(wasm, arg_id); - const diplomat_out = (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCustomTimeZone_try_set_time_zone_id(diplomat_receive_buffer, this.underlying, buf_arg_id.ptr, buf_arg_id.size); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = {}; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = TimeZoneInvalidIdError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - buf_arg_id.free(); - return diplomat_out; - } - - try_set_iana_time_zone_id(arg_mapper, arg_id) { - const buf_arg_id = diplomatRuntime.DiplomatBuf.str8(wasm, arg_id); - const diplomat_out = (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCustomTimeZone_try_set_iana_time_zone_id(diplomat_receive_buffer, this.underlying, arg_mapper.underlying, buf_arg_id.ptr, buf_arg_id.size); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = {}; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = TimeZoneInvalidIdError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - buf_arg_id.free(); - return diplomat_out; - } - - clear_time_zone_id() { - wasm.ICU4XCustomTimeZone_clear_time_zone_id(this.underlying); - } - - time_zone_id() { - return diplomatRuntime.withDiplomatWrite(wasm, (write) => { - return (() => { - const is_ok = wasm.ICU4XCustomTimeZone_time_zone_id(this.underlying, write) == 1; - if (!is_ok) return; - })(); - }); - } - - try_set_metazone_id(arg_id) { - const buf_arg_id = diplomatRuntime.DiplomatBuf.str8(wasm, arg_id); - const diplomat_out = (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCustomTimeZone_try_set_metazone_id(diplomat_receive_buffer, this.underlying, buf_arg_id.ptr, buf_arg_id.size); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = {}; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = TimeZoneInvalidIdError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - buf_arg_id.free(); - return diplomat_out; - } - - clear_metazone_id() { - wasm.ICU4XCustomTimeZone_clear_metazone_id(this.underlying); - } - - metazone_id() { - return diplomatRuntime.withDiplomatWrite(wasm, (write) => { - return (() => { - const is_ok = wasm.ICU4XCustomTimeZone_metazone_id(this.underlying, write) == 1; - if (!is_ok) return; - })(); - }); - } - - try_set_zone_variant(arg_id) { - const buf_arg_id = diplomatRuntime.DiplomatBuf.str8(wasm, arg_id); - const diplomat_out = (() => { - const is_ok = wasm.ICU4XCustomTimeZone_try_set_zone_variant(this.underlying, buf_arg_id.ptr, buf_arg_id.size) == 1; - if (!is_ok) return; - })(); - buf_arg_id.free(); - return diplomat_out; - } - - clear_zone_variant() { - wasm.ICU4XCustomTimeZone_clear_zone_variant(this.underlying); - } - - zone_variant() { - return diplomatRuntime.withDiplomatWrite(wasm, (write) => { - return (() => { - const is_ok = wasm.ICU4XCustomTimeZone_zone_variant(this.underlying, write) == 1; - if (!is_ok) return; - })(); - }); - } - - set_standard_time() { - wasm.ICU4XCustomTimeZone_set_standard_time(this.underlying); - } - - set_daylight_time() { - wasm.ICU4XCustomTimeZone_set_daylight_time(this.underlying); - } - - is_standard_time() { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(2, 1); - wasm.ICU4XCustomTimeZone_is_standard_time(diplomat_receive_buffer, this.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 1); - if (!is_ok) { - wasm.diplomat_free(diplomat_receive_buffer, 2, 1); - return; - } - const value = (new Uint8Array(wasm.memory.buffer, diplomat_receive_buffer, 1))[0] == 1; - wasm.diplomat_free(diplomat_receive_buffer, 2, 1); - return value; - })(); - } - - is_daylight_time() { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(2, 1); - wasm.ICU4XCustomTimeZone_is_daylight_time(diplomat_receive_buffer, this.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 1); - if (!is_ok) { - wasm.diplomat_free(diplomat_receive_buffer, 2, 1); - return; - } - const value = (new Uint8Array(wasm.memory.buffer, diplomat_receive_buffer, 1))[0] == 1; - wasm.diplomat_free(diplomat_receive_buffer, 2, 1); - return value; - })(); - } - - maybe_calculate_metazone(arg_metazone_calculator, arg_local_datetime) { - wasm.ICU4XCustomTimeZone_maybe_calculate_metazone(this.underlying, arg_metazone_calculator.underlying, arg_local_datetime.underlying); - } -} + + trySetTimeZoneId(id) { + + const idSlice = diplomatRuntime.DiplomatBuf.str8(wasm, id); + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCustomTimeZone_try_set_time_zone_id(diplomat_receive_buffer, this.ffiValue, idSlice.ptr, idSlice.size); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = TimeZoneInvalidIdError[Array.from(TimeZoneInvalidIdError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('TimeZoneInvalidIdError: ' + cause.value, { cause }); + } + + } finally { + + idSlice.free(); + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + trySetIanaTimeZoneId(mapper, id) { + + const idSlice = diplomatRuntime.DiplomatBuf.str8(wasm, id); + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCustomTimeZone_try_set_iana_time_zone_id(diplomat_receive_buffer, this.ffiValue, mapper.ffiValue, idSlice.ptr, idSlice.size); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = TimeZoneInvalidIdError[Array.from(TimeZoneInvalidIdError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('TimeZoneInvalidIdError: ' + cause.value, { cause }); + } + + } finally { + + idSlice.free(); + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + clearTimeZoneId() { + wasm.ICU4XCustomTimeZone_clear_time_zone_id(this.ffiValue); + + try { + + } finally { + + } + } + + get timeZoneId() { + + const write = wasm.diplomat_buffer_write_create(0); + const result = wasm.ICU4XCustomTimeZone_time_zone_id(this.ffiValue, write); + + try { + + return result == 0 ? null : diplomatRuntime.readString8(wasm, wasm.diplomat_buffer_write_get_bytes(write), wasm.diplomat_buffer_write_len(write)); + } finally { + + wasm.diplomat_buffer_write_destroy(write); + + } + } + + trySetMetazoneId(id) { + + const idSlice = diplomatRuntime.DiplomatBuf.str8(wasm, id); + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XCustomTimeZone_try_set_metazone_id(diplomat_receive_buffer, this.ffiValue, idSlice.ptr, idSlice.size); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = TimeZoneInvalidIdError[Array.from(TimeZoneInvalidIdError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('TimeZoneInvalidIdError: ' + cause.value, { cause }); + } + + } finally { + + idSlice.free(); + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + clearMetazoneId() { + wasm.ICU4XCustomTimeZone_clear_metazone_id(this.ffiValue); + + try { + + } finally { + + } + } + + get metazoneId() { + + const write = wasm.diplomat_buffer_write_create(0); + const result = wasm.ICU4XCustomTimeZone_metazone_id(this.ffiValue, write); + + try { + + return result == 0 ? null : diplomatRuntime.readString8(wasm, wasm.diplomat_buffer_write_get_bytes(write), wasm.diplomat_buffer_write_len(write)); + } finally { + + wasm.diplomat_buffer_write_destroy(write); + + } + } + + trySetZoneVariant(id) { + + const idSlice = diplomatRuntime.DiplomatBuf.str8(wasm, id); + const result = wasm.ICU4XCustomTimeZone_try_set_zone_variant(this.ffiValue, idSlice.ptr, idSlice.size); + + try { + + return result == 1; + } finally { + + idSlice.free(); + + } + } + + clearZoneVariant() { + wasm.ICU4XCustomTimeZone_clear_zone_variant(this.ffiValue); + + try { + + } finally { + + } + } + + get zoneVariant() { + + const write = wasm.diplomat_buffer_write_create(0); + const result = wasm.ICU4XCustomTimeZone_zone_variant(this.ffiValue, write); + + try { + + return result == 0 ? null : diplomatRuntime.readString8(wasm, wasm.diplomat_buffer_write_get_bytes(write), wasm.diplomat_buffer_write_len(write)); + } finally { + + wasm.diplomat_buffer_write_destroy(write); + + } + } + + setStandardTime() { + wasm.ICU4XCustomTimeZone_set_standard_time(this.ffiValue); + + try { + + } finally { + + } + } + + setDaylightTime() { + wasm.ICU4XCustomTimeZone_set_daylight_time(this.ffiValue); + + try { + + } finally { + + } + } + + get isStandardTime() { + + const diplomat_receive_buffer = wasm.diplomat_alloc(2, 1); + const result = wasm.ICU4XCustomTimeZone_is_standard_time(diplomat_receive_buffer, this.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 1)) { + return null; + } + return (new Uint8Array(wasm.memory.buffer, diplomat_receive_buffer, 1))[0] == 1; + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 2, 1); + + } + } + + get isDaylightTime() { + + const diplomat_receive_buffer = wasm.diplomat_alloc(2, 1); + const result = wasm.ICU4XCustomTimeZone_is_daylight_time(diplomat_receive_buffer, this.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 1)) { + return null; + } + return (new Uint8Array(wasm.memory.buffer, diplomat_receive_buffer, 1))[0] == 1; + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 2, 1); + + } + } + + maybeCalculateMetazone(metazoneCalculator, localDatetime) { + wasm.ICU4XCustomTimeZone_maybe_calculate_metazone(this.ffiValue, metazoneCalculator.ffiValue, localDatetime.ffiValue); + + try { + + } finally { + + } + } + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/DataError.d.ts b/ffi/capi/bindings/js/DataError.d.ts index a533512bd6f..db9709399f0 100644 --- a/ffi/capi/bindings/js/DataError.d.ts +++ b/ffi/capi/bindings/js/DataError.d.ts @@ -1,34 +1,35 @@ +// generated by diplomat-tool +import type { pointer, char } from "./diplomat-runtime.d.ts"; + +// Base enumerator definition +/** Additional information: [1](https://docs.rs/icu/latest/icu/provider/struct.DataError.html), [2](https://docs.rs/icu/latest/icu/provider/enum.DataErrorKind.html) +*/ +export class DataError { + constructor(value : DataError | string); + + get value() : string; + + get ffiValue() : number; + + static Unknown : DataError; + + static MarkerNotFound : DataError; + + static IdentifierNotFound : DataError; + + static InvalidRequest : DataError; + + static InconsistentData : DataError; + + static Downcast : DataError; + + static Deserialize : DataError; + + static Custom : DataError; + + static Io : DataError; + + + -/** - - * Additional information: {@link https://docs.rs/icu/latest/icu/provider/struct.DataError.html 1}, {@link https://docs.rs/icu/latest/icu/provider/enum.DataErrorKind.html 2} - */ -export enum DataError { - /** - */ - Unknown = 'Unknown', - /** - */ - MarkerNotFound = 'MarkerNotFound', - /** - */ - IdentifierNotFound = 'IdentifierNotFound', - /** - */ - InvalidRequest = 'InvalidRequest', - /** - */ - InconsistentData = 'InconsistentData', - /** - */ - Downcast = 'Downcast', - /** - */ - Deserialize = 'Deserialize', - /** - */ - Custom = 'Custom', - /** - */ - Io = 'Io', } \ No newline at end of file diff --git a/ffi/capi/bindings/js/DataError.mjs b/ffi/capi/bindings/js/DataError.mjs index f286c391479..6baf76765ea 100644 --- a/ffi/capi/bindings/js/DataError.mjs +++ b/ffi/capi/bindings/js/DataError.mjs @@ -1,38 +1,65 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" - -export const DataError_js_to_rust = { - "Unknown": 0, - "MarkerNotFound": 1, - "IdentifierNotFound": 2, - "InvalidRequest": 3, - "InconsistentData": 4, - "Downcast": 5, - "Deserialize": 6, - "Custom": 7, - "Io": 8, -}; - -export const DataError_rust_to_js = { - [0]: "Unknown", - [1]: "MarkerNotFound", - [2]: "IdentifierNotFound", - [3]: "InvalidRequest", - [4]: "InconsistentData", - [5]: "Downcast", - [6]: "Deserialize", - [7]: "Custom", - [8]: "Io", -}; - -export const DataError = { - "Unknown": "Unknown", - "MarkerNotFound": "MarkerNotFound", - "IdentifierNotFound": "IdentifierNotFound", - "InvalidRequest": "InvalidRequest", - "InconsistentData": "InconsistentData", - "Downcast": "Downcast", - "Deserialize": "Deserialize", - "Custom": "Custom", - "Io": "Io", -}; +// generated by diplomat-tool +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; + +// Base enumerator definition +/** Additional information: [1](https://docs.rs/icu/latest/icu/provider/struct.DataError.html), [2](https://docs.rs/icu/latest/icu/provider/enum.DataErrorKind.html) +*/ +export class DataError { + #value = undefined; + + static values = new Map([ + ["Unknown", 0], + ["MarkerNotFound", 1], + ["IdentifierNotFound", 2], + ["InvalidRequest", 3], + ["InconsistentData", 4], + ["Downcast", 5], + ["Deserialize", 6], + ["Custom", 7], + ["Io", 8] + ]); + constructor(value) { + if (value instanceof DataError) { + this.#value = value.value; + return; + } + + if (DataError.values.has(value)) { + this.#value = value; + return; + } + + throw TypeError(value + " is not a DataError and does not correspond to any of its enumerator values."); + } + + get value() { + return this.#value; + } + + get ffiValue() { + return DataError.values.get(this.#value); + } + + static Unknown = new DataError("Unknown"); + + static MarkerNotFound = new DataError("MarkerNotFound"); + + static IdentifierNotFound = new DataError("IdentifierNotFound"); + + static InvalidRequest = new DataError("InvalidRequest"); + + static InconsistentData = new DataError("InconsistentData"); + + static Downcast = new DataError("Downcast"); + + static Deserialize = new DataError("Deserialize"); + + static Custom = new DataError("Custom"); + + static Io = new DataError("Io"); + + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/DataProvider.d.ts b/ffi/capi/bindings/js/DataProvider.d.ts index 61b5168fb1e..26b53a3960c 100644 --- a/ffi/capi/bindings/js/DataProvider.d.ts +++ b/ffi/capi/bindings/js/DataProvider.d.ts @@ -1,79 +1,30 @@ -import { FFIError } from "./diplomat-runtime" -import { DataError } from "./DataError"; -import { LocaleFallbacker } from "./LocaleFallbacker"; +// generated by diplomat-tool +import type { LocaleFallbacker } from "./LocaleFallbacker" +import type { pointer, char } from "./diplomat-runtime.d.ts"; -/** - * An ICU4X data provider, capable of loading ICU4X data keys from some source. - - * See the {@link https://docs.rs/icu_provider/latest/icu_provider/index.html Rust documentation for `icu_provider`} for more information. - */ +/** An ICU4X data provider, capable of loading ICU4X data keys from some source. +* +*See the [Rust documentation for `icu_provider`](https://docs.rs/icu_provider/latest/icu_provider/index.html) for more information. +*/ export class DataProvider { + - /** - - * Constructs an {@link DataProvider `DataProvider`} that uses compiled data. - - * Requires the `compiled_data` feature. - - * This provider cannot be modified or combined with other providers, so `enable_fallback`, `enabled_fallback_with`, `fork_by_locale`, and `fork_by_key` will return `Err`s. - */ - static create_compiled(): DataProvider; - - /** - - * Constructs an `FsDataProvider` and returns it as an {@link DataProvider `DataProvider`}. Requires the `provider_fs` Cargo feature. Not supported in WASM. - - * See the {@link https://docs.rs/icu_provider_fs/latest/icu_provider_fs/struct.FsDataProvider.html Rust documentation for `FsDataProvider`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static create_fs(path: string): DataProvider | never; - - /** - - * Constructs a `BlobDataProvider` and returns it as an {@link DataProvider `DataProvider`}. - - * See the {@link https://docs.rs/icu_provider_blob/latest/icu_provider_blob/struct.BlobDataProvider.html Rust documentation for `BlobDataProvider`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static create_from_byte_slice(blob: Uint8Array): DataProvider | never; - - /** - - * Constructs an empty {@link DataProvider `DataProvider`}. - - * See the {@link https://docs.rs/icu_provider_adapters/latest/icu_provider_adapters/empty/struct.EmptyDataProvider.html Rust documentation for `EmptyDataProvider`} for more information. - */ - static create_empty(): DataProvider; - - /** - - * Creates a provider that tries the current provider and then, if the current provider doesn't support the data key, another provider `other`. + get ffiValue(): pointer; - * This takes ownership of the `other` provider, leaving an empty provider in its place. - * The providers must be the same type (Any or Buffer). This condition is satisfied if both providers originate from the same constructor, such as `create_from_byte_slice` or `create_fs`. If the condition is not upheld, a runtime error occurs. + static createCompiled(): DataProvider; - * See the {@link https://docs.rs/icu_provider_adapters/latest/icu_provider_adapters/fork/type.ForkByMarkerProvider.html Rust documentation for `ForkByMarkerProvider`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - fork_by_key(other: DataProvider): void | never; + static createFromByteSlice(blob: Uint8Array): DataProvider; - /** + static createEmpty(): DataProvider; - * Same as `fork_by_key` but forks by locale instead of key. + forkByKey(other: DataProvider): void; - * See the {@link https://docs.rs/icu_provider_adapters/latest/icu_provider_adapters/fork/predicates/struct.IdentifierNotFoundPredicate.html Rust documentation for `IdentifierNotFoundPredicate`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - fork_by_locale(other: DataProvider): void | never; + forkByLocale(other: DataProvider): void; - /** + enableLocaleFallbackWith(fallbacker: LocaleFallbacker): void; - * See the {@link https://docs.rs/icu_provider_adapters/latest/icu_provider_adapters/fallback/struct.LocaleFallbackProvider.html#method.new Rust documentation for `new`} for more information. + - * Additional information: {@link https://docs.rs/icu_provider_adapters/latest/icu_provider_adapters/fallback/struct.LocaleFallbackProvider.html 1} - * @throws {@link FFIError}<{@link DataError}> - */ - enable_locale_fallback_with(fallbacker: LocaleFallbacker): void | never; -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/DataProvider.mjs b/ffi/capi/bindings/js/DataProvider.mjs index b30a66efa13..6119f8ab47f 100644 --- a/ffi/capi/bindings/js/DataProvider.mjs +++ b/ffi/capi/bindings/js/DataProvider.mjs @@ -1,117 +1,142 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" -import { DataError_js_to_rust, DataError_rust_to_js } from "./DataError.mjs" +// generated by diplomat-tool +import { DataError } from "./DataError.mjs" +import { LocaleFallbacker } from "./LocaleFallbacker.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -const DataProvider_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XDataProvider_destroy(underlying); -}); +/** An ICU4X data provider, capable of loading ICU4X data keys from some source. +* +*See the [Rust documentation for `icu_provider`](https://docs.rs/icu_provider/latest/icu_provider/index.html) for more information. +*/ + +const DataProvider_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XDataProvider_destroy(ptr); +}); export class DataProvider { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - DataProvider_box_destroy_registry.register(this, underlying); + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + + constructor(ptr, selfEdge) { + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + DataProvider_box_destroy_registry.register(this, this.#ptr); + } + + get ffiValue() { + return this.#ptr; + } + + + static createCompiled() { + const result = wasm.ICU4XDataProvider_create_compiled(); + + try { + + return new DataProvider(result, []); + } finally { + + } } - } - static create_compiled() { - return new DataProvider(wasm.ICU4XDataProvider_create_compiled(), true, []); - } + static createFromByteSlice(blob) { + + const blobSlice = diplomatRuntime.DiplomatBuf.slice(wasm, blob, "u8"); + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XDataProvider_create_from_byte_slice(diplomat_receive_buffer, blobSlice.ptr, blobSlice.size); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new DataProvider(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + blobSlice.free(); + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } - static create_fs(arg_path) { - const buf_arg_path = diplomatRuntime.DiplomatBuf.str8(wasm, arg_path); - const diplomat_out = (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XDataProvider_create_fs(diplomat_receive_buffer, buf_arg_path.ptr, buf_arg_path.size); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new DataProvider(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - buf_arg_path.free(); - return diplomat_out; - } + static createEmpty() { + const result = wasm.ICU4XDataProvider_create_empty(); + + try { + + return new DataProvider(result, []); + } finally { + + } + } - static create_from_byte_slice(arg_blob) { - const buf_arg_blob = diplomatRuntime.DiplomatBuf.slice(wasm, arg_blob, "u8"); - const diplomat_out = (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XDataProvider_create_from_byte_slice(diplomat_receive_buffer, buf_arg_blob.ptr, buf_arg_blob.size); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new DataProvider(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - buf_arg_blob.leak(); - return diplomat_out; - } + forkByKey(other) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XDataProvider_fork_by_key(diplomat_receive_buffer, this.ffiValue, other.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } - static create_empty() { - return new DataProvider(wasm.ICU4XDataProvider_create_empty(), true, []); - } + forkByLocale(other) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XDataProvider_fork_by_locale(diplomat_receive_buffer, this.ffiValue, other.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } - fork_by_key(arg_other) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XDataProvider_fork_by_key(diplomat_receive_buffer, this.underlying, arg_other.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = {}; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } + enableLocaleFallbackWith(fallbacker) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XDataProvider_enable_locale_fallback_with(diplomat_receive_buffer, this.ffiValue, fallbacker.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } - fork_by_locale(arg_other) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XDataProvider_fork_by_locale(diplomat_receive_buffer, this.underlying, arg_other.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = {}; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } + - enable_locale_fallback_with(arg_fallbacker) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XDataProvider_enable_locale_fallback_with(diplomat_receive_buffer, this.underlying, arg_fallbacker.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = {}; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/DataStruct.d.ts b/ffi/capi/bindings/js/DataStruct.d.ts deleted file mode 100644 index 9fe9f2aa201..00000000000 --- a/ffi/capi/bindings/js/DataStruct.d.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { u8 } from "./diplomat-runtime" - -/** - - * A generic data struct to be used by ICU4X - - * This can be used to construct a StructDataProvider. - */ -export class DataStruct { - - /** - - * Construct a new DecimalSymbolsV1 data struct. - - * Ill-formed input is treated as if errors had been replaced with REPLACEMENT CHARACTERs according to the WHATWG Encoding Standard. - - * Digits needs to be a 10-character-long slice of valid Unicode characters, otherwise null is returned. - - * See the {@link https://docs.rs/icu/latest/icu/decimal/provider/struct.DecimalSymbolsV1.html Rust documentation for `DecimalSymbolsV1`} for more information. - */ - static create_decimal_symbols_v1(plus_sign_prefix: string, plus_sign_suffix: string, minus_sign_prefix: string, minus_sign_suffix: string, decimal_separator: string, grouping_separator: string, primary_group_size: u8, secondary_group_size: u8, min_group_size: u8, digits: Uint32Array): DataStruct | undefined; -} diff --git a/ffi/capi/bindings/js/DataStruct.mjs b/ffi/capi/bindings/js/DataStruct.mjs deleted file mode 100644 index fa64dedd1a6..00000000000 --- a/ffi/capi/bindings/js/DataStruct.mjs +++ /dev/null @@ -1,39 +0,0 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" - -const DataStruct_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XDataStruct_destroy(underlying); -}); - -export class DataStruct { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - DataStruct_box_destroy_registry.register(this, underlying); - } - } - - static create_decimal_symbols_v1(arg_plus_sign_prefix, arg_plus_sign_suffix, arg_minus_sign_prefix, arg_minus_sign_suffix, arg_decimal_separator, arg_grouping_separator, arg_primary_group_size, arg_secondary_group_size, arg_min_group_size, arg_digits) { - const buf_arg_plus_sign_prefix = diplomatRuntime.DiplomatBuf.str8(wasm, arg_plus_sign_prefix); - const buf_arg_plus_sign_suffix = diplomatRuntime.DiplomatBuf.str8(wasm, arg_plus_sign_suffix); - const buf_arg_minus_sign_prefix = diplomatRuntime.DiplomatBuf.str8(wasm, arg_minus_sign_prefix); - const buf_arg_minus_sign_suffix = diplomatRuntime.DiplomatBuf.str8(wasm, arg_minus_sign_suffix); - const buf_arg_decimal_separator = diplomatRuntime.DiplomatBuf.str8(wasm, arg_decimal_separator); - const buf_arg_grouping_separator = diplomatRuntime.DiplomatBuf.str8(wasm, arg_grouping_separator); - const buf_arg_digits = diplomatRuntime.DiplomatBuf.slice(wasm, arg_digits, "char"); - const diplomat_out = (() => { - const option_ptr = wasm.ICU4XDataStruct_create_decimal_symbols_v1(buf_arg_plus_sign_prefix.ptr, buf_arg_plus_sign_prefix.size, buf_arg_plus_sign_suffix.ptr, buf_arg_plus_sign_suffix.size, buf_arg_minus_sign_prefix.ptr, buf_arg_minus_sign_prefix.size, buf_arg_minus_sign_suffix.ptr, buf_arg_minus_sign_suffix.size, buf_arg_decimal_separator.ptr, buf_arg_decimal_separator.size, buf_arg_grouping_separator.ptr, buf_arg_grouping_separator.size, arg_primary_group_size, arg_secondary_group_size, arg_min_group_size, buf_arg_digits.ptr, buf_arg_digits.size); - return (option_ptr == 0) ? undefined : new DataStruct(option_ptr, true, []); - })(); - buf_arg_plus_sign_prefix.free(); - buf_arg_plus_sign_suffix.free(); - buf_arg_minus_sign_prefix.free(); - buf_arg_minus_sign_suffix.free(); - buf_arg_decimal_separator.free(); - buf_arg_grouping_separator.free(); - buf_arg_digits.free(); - return diplomat_out; - } -} diff --git a/ffi/capi/bindings/js/Date.d.ts b/ffi/capi/bindings/js/Date.d.ts index c5a3490347a..f843f3f967e 100644 --- a/ffi/capi/bindings/js/Date.d.ts +++ b/ffi/capi/bindings/js/Date.d.ts @@ -1,161 +1,56 @@ -import { u8, u16, i32, u32 } from "./diplomat-runtime" -import { FFIError } from "./diplomat-runtime" -import { Calendar } from "./Calendar"; -import { CalendarError } from "./CalendarError"; -import { IsoDate } from "./IsoDate"; -import { IsoWeekday } from "./IsoWeekday"; -import { WeekCalculator } from "./WeekCalculator"; -import { WeekOf } from "./WeekOf"; - -/** - - * An ICU4X Date object capable of containing a date and time for any calendar. - - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.Date.html Rust documentation for `Date`} for more information. - */ +// generated by diplomat-tool +import type { Calendar } from "./Calendar" +import type { IsoDate } from "./IsoDate" +import type { IsoWeekday } from "./IsoWeekday" +import type { WeekCalculator } from "./WeekCalculator" +import type { WeekOf } from "./WeekOf" +import type { pointer, char } from "./diplomat-runtime.d.ts"; + + +/** An ICU4X Date object capable of containing a date and time for any calendar. +* +*See the [Rust documentation for `Date`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html) for more information. +*/ export class Date { + - /** - - * Creates a new {@link Date `Date`} representing the ISO date and time given but in a given calendar - - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.new_from_iso Rust documentation for `new_from_iso`} for more information. - * @throws {@link FFIError}<{@link CalendarError}> - */ - static create_from_iso_in_calendar(year: i32, month: u8, day: u8, calendar: Calendar): Date | never; - - /** - - * Creates a new {@link Date `Date`} from the given codes, which are interpreted in the given calendar system - - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.try_new_from_codes Rust documentation for `try_new_from_codes`} for more information. - * @throws {@link FFIError}<{@link CalendarError}> - */ - static create_from_codes_in_calendar(era_code: string, year: i32, month_code: string, day: u8, calendar: Calendar): Date | never; - - /** - - * Convert this date to one in a different calendar - - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.to_calendar Rust documentation for `to_calendar`} for more information. - */ - to_calendar(calendar: Calendar): Date; - - /** - - * Converts this date to ISO - - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.to_iso Rust documentation for `to_iso`} for more information. - */ - to_iso(): IsoDate; - - /** - - * Returns the 1-indexed day in the year for this date - - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.day_of_year_info Rust documentation for `day_of_year_info`} for more information. - */ - day_of_year(): u16; - - /** - - * Returns the 1-indexed day in the month for this date - - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.day_of_month Rust documentation for `day_of_month`} for more information. - */ - day_of_month(): u32; - - /** - - * Returns the day in the week for this day - - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.day_of_week Rust documentation for `day_of_week`} for more information. - */ - day_of_week(): IsoWeekday; - - /** - - * Returns the week number in this month, 1-indexed, based on what is considered the first day of the week (often a locale preference). - - * `first_weekday` can be obtained via `first_weekday()` on {@link WeekCalculator `WeekCalculator`} - - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.week_of_month Rust documentation for `week_of_month`} for more information. - */ - week_of_month(first_weekday: IsoWeekday): u32; - - /** - - * Returns the week number in this year, using week data - - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.week_of_year Rust documentation for `week_of_year`} for more information. - */ - week_of_year(calculator: WeekCalculator): WeekOf; - - /** - - * Returns 1-indexed number of the month of this date in its year - - * Note that for lunar calendars this may not lead to the same month having the same ordinal month across years; use month_code if you care about month identity. - - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.month Rust documentation for `month`} for more information. - */ - ordinal_month(): u32; - - /** - - * Returns the month code for this date. Typically something like "M01", "M02", but can be more complicated for lunar calendars. + get ffiValue(): pointer; - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.month Rust documentation for `month`} for more information. - */ - month_code(): string; - /** + static createFromIsoInCalendar(year: number, month: number, day: number, calendar: Calendar): Date; - * Returns the year number in the current era for this date + static createFromCodesInCalendar(eraCode: string, year: number, monthCode: string, day: number, calendar: Calendar): Date; - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.year Rust documentation for `year`} for more information. - */ - year_in_era(): i32; + toCalendar(calendar: Calendar): Date; - /** + toIso(): IsoDate; - * Returns the era for this date, + get dayOfYear(): number; - * See the {@link https://docs.rs/icu/latest/icu/struct.Date.html#method.year Rust documentation for `year`} for more information. + get dayOfMonth(): number; - * Additional information: {@link https://docs.rs/icu/latest/icu/types/struct.Era.html 1} - */ - era(): string; + get dayOfWeek(): IsoWeekday; - /** + weekOfMonth(firstWeekday: IsoWeekday): number; - * Returns the number of months in the year represented by this date + weekOfYear(calculator: WeekCalculator): WeekOf; - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.months_in_year Rust documentation for `months_in_year`} for more information. - */ - months_in_year(): u8; + get ordinalMonth(): number; - /** + get monthCode(): string; - * Returns the number of days in the month represented by this date + get yearInEra(): number; - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.days_in_month Rust documentation for `days_in_month`} for more information. - */ - days_in_month(): u8; + get era(): string; - /** + get monthsInYear(): number; - * Returns the number of days in the year represented by this date + get daysInMonth(): number; - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.days_in_year Rust documentation for `days_in_year`} for more information. - */ - days_in_year(): u16; + get daysInYear(): number; - /** + get calendar(): Calendar; - * Returns the {@link Calendar `Calendar`} object backing this date + - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.calendar Rust documentation for `calendar`} for more information. - */ - calendar(): Calendar; -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/Date.mjs b/ffi/capi/bindings/js/Date.mjs index 9d1ae657fc2..d40f8712159 100644 --- a/ffi/capi/bindings/js/Date.mjs +++ b/ffi/capi/bindings/js/Date.mjs @@ -1,132 +1,267 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" +// generated by diplomat-tool import { Calendar } from "./Calendar.mjs" -import { CalendarError_js_to_rust, CalendarError_rust_to_js } from "./CalendarError.mjs" +import { CalendarError } from "./CalendarError.mjs" import { IsoDate } from "./IsoDate.mjs" -import { IsoWeekday_js_to_rust, IsoWeekday_rust_to_js } from "./IsoWeekday.mjs" +import { IsoWeekday } from "./IsoWeekday.mjs" +import { WeekCalculator } from "./WeekCalculator.mjs" import { WeekOf } from "./WeekOf.mjs" -import { WeekRelativeUnit_js_to_rust, WeekRelativeUnit_rust_to_js } from "./WeekRelativeUnit.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -const Date_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XDate_destroy(underlying); -}); +/** An ICU4X Date object capable of containing a date and time for any calendar. +* +*See the [Rust documentation for `Date`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html) for more information. +*/ + +const Date_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XDate_destroy(ptr); +}); export class Date { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - Date_box_destroy_registry.register(this, underlying); - } - } - - static create_from_iso_in_calendar(arg_year, arg_month, arg_day, arg_calendar) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XDate_create_from_iso_in_calendar(diplomat_receive_buffer, arg_year, arg_month, arg_day, arg_calendar.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new Date(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = CalendarError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static create_from_codes_in_calendar(arg_era_code, arg_year, arg_month_code, arg_day, arg_calendar) { - const buf_arg_era_code = diplomatRuntime.DiplomatBuf.str8(wasm, arg_era_code); - const buf_arg_month_code = diplomatRuntime.DiplomatBuf.str8(wasm, arg_month_code); - const diplomat_out = (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XDate_create_from_codes_in_calendar(diplomat_receive_buffer, buf_arg_era_code.ptr, buf_arg_era_code.size, arg_year, buf_arg_month_code.ptr, buf_arg_month_code.size, arg_day, arg_calendar.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new Date(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = CalendarError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - buf_arg_era_code.free(); - buf_arg_month_code.free(); - return diplomat_out; - } - - to_calendar(arg_calendar) { - return new Date(wasm.ICU4XDate_to_calendar(this.underlying, arg_calendar.underlying), true, []); - } - - to_iso() { - return new IsoDate(wasm.ICU4XDate_to_iso(this.underlying), true, []); - } - - day_of_year() { - return wasm.ICU4XDate_day_of_year(this.underlying); - } - - day_of_month() { - return wasm.ICU4XDate_day_of_month(this.underlying); - } - - day_of_week() { - return IsoWeekday_rust_to_js[wasm.ICU4XDate_day_of_week(this.underlying)]; - } - - week_of_month(arg_first_weekday) { - return wasm.ICU4XDate_week_of_month(this.underlying, IsoWeekday_js_to_rust[arg_first_weekday]); - } - - week_of_year(arg_calculator) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(8, 4); - wasm.ICU4XDate_week_of_year(diplomat_receive_buffer, this.underlying, arg_calculator.underlying); - const out = new WeekOf(diplomat_receive_buffer); - wasm.diplomat_free(diplomat_receive_buffer, 8, 4); - return out; - })(); - } - - ordinal_month() { - return wasm.ICU4XDate_ordinal_month(this.underlying); - } - - month_code() { - return diplomatRuntime.withDiplomatWrite(wasm, (write) => { - return wasm.ICU4XDate_month_code(this.underlying, write); - }); - } - - year_in_era() { - return wasm.ICU4XDate_year_in_era(this.underlying); - } - - era() { - return diplomatRuntime.withDiplomatWrite(wasm, (write) => { - return wasm.ICU4XDate_era(this.underlying, write); - }); - } - - months_in_year() { - return wasm.ICU4XDate_months_in_year(this.underlying); - } - - days_in_month() { - return wasm.ICU4XDate_days_in_month(this.underlying); - } - - days_in_year() { - return wasm.ICU4XDate_days_in_year(this.underlying); - } - - calendar() { - return new Calendar(wasm.ICU4XDate_calendar(this.underlying), true, []); - } -} + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + + constructor(ptr, selfEdge) { + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + Date_box_destroy_registry.register(this, this.#ptr); + } + + get ffiValue() { + return this.#ptr; + } + + + static createFromIsoInCalendar(year, month, day, calendar) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XDate_create_from_iso_in_calendar(diplomat_receive_buffer, year, month, day, calendar.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = CalendarError[Array.from(CalendarError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('CalendarError: ' + cause.value, { cause }); + } + return new Date(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static createFromCodesInCalendar(eraCode, year, monthCode, day, calendar) { + + const eraCodeSlice = diplomatRuntime.DiplomatBuf.str8(wasm, eraCode); + + const monthCodeSlice = diplomatRuntime.DiplomatBuf.str8(wasm, monthCode); + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XDate_create_from_codes_in_calendar(diplomat_receive_buffer, eraCodeSlice.ptr, eraCodeSlice.size, year, monthCodeSlice.ptr, monthCodeSlice.size, day, calendar.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = CalendarError[Array.from(CalendarError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('CalendarError: ' + cause.value, { cause }); + } + return new Date(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + eraCodeSlice.free(); + + monthCodeSlice.free(); + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + toCalendar(calendar) { + const result = wasm.ICU4XDate_to_calendar(this.ffiValue, calendar.ffiValue); + + try { + + return new Date(result, []); + } finally { + + } + } + + toIso() { + const result = wasm.ICU4XDate_to_iso(this.ffiValue); + + try { + + return new IsoDate(result, []); + } finally { + + } + } + + get dayOfYear() { + const result = wasm.ICU4XDate_day_of_year(this.ffiValue); + + try { + + return result; + } finally { + + } + } + + get dayOfMonth() { + const result = wasm.ICU4XDate_day_of_month(this.ffiValue); + + try { + + return result; + } finally { + + } + } + + get dayOfWeek() { + const result = wasm.ICU4XDate_day_of_week(this.ffiValue); + + try { + + return (() => {for (let i of IsoWeekday.values) { if(i[1] === result) return IsoWeekday[i[0]]; } return null;})(); + } finally { + + } + } + + weekOfMonth(firstWeekday) { + const result = wasm.ICU4XDate_week_of_month(this.ffiValue, firstWeekday.ffiValue); + + try { + + return result; + } finally { + + } + } + + weekOfYear(calculator) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(8, 4); + const result = wasm.ICU4XDate_week_of_year(diplomat_receive_buffer, this.ffiValue, calculator.ffiValue); + + try { + + return new WeekOf(diplomat_receive_buffer); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 8, 4); + + } + } + + get ordinalMonth() { + const result = wasm.ICU4XDate_ordinal_month(this.ffiValue); + + try { + + return result; + } finally { + + } + } + + get monthCode() { + + const write = wasm.diplomat_buffer_write_create(0); + wasm.ICU4XDate_month_code(this.ffiValue, write); + + try { + + return diplomatRuntime.readString8(wasm, wasm.diplomat_buffer_write_get_bytes(write), wasm.diplomat_buffer_write_len(write)); + } finally { + + wasm.diplomat_buffer_write_destroy(write); + + } + } + + get yearInEra() { + const result = wasm.ICU4XDate_year_in_era(this.ffiValue); + + try { + + return result; + } finally { + + } + } + + get era() { + + const write = wasm.diplomat_buffer_write_create(0); + wasm.ICU4XDate_era(this.ffiValue, write); + + try { + + return diplomatRuntime.readString8(wasm, wasm.diplomat_buffer_write_get_bytes(write), wasm.diplomat_buffer_write_len(write)); + } finally { + + wasm.diplomat_buffer_write_destroy(write); + + } + } + + get monthsInYear() { + const result = wasm.ICU4XDate_months_in_year(this.ffiValue); + + try { + + return result; + } finally { + + } + } + + get daysInMonth() { + const result = wasm.ICU4XDate_days_in_month(this.ffiValue); + + try { + + return result; + } finally { + + } + } + + get daysInYear() { + const result = wasm.ICU4XDate_days_in_year(this.ffiValue); + + try { + + return result; + } finally { + + } + } + + get calendar() { + const result = wasm.ICU4XDate_calendar(this.ffiValue); + + try { + + return new Calendar(result, []); + } finally { + + } + } + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/DateFormatter.d.ts b/ffi/capi/bindings/js/DateFormatter.d.ts index 8bd40c79936..ad07401ca95 100644 --- a/ffi/capi/bindings/js/DateFormatter.d.ts +++ b/ffi/capi/bindings/js/DateFormatter.d.ts @@ -1,67 +1,35 @@ -import { FFIError } from "./diplomat-runtime" -import { DataProvider } from "./DataProvider"; -import { Date } from "./Date"; -import { DateLength } from "./DateLength"; -import { DateTime } from "./DateTime"; -import { Error } from "./Error"; -import { IsoDate } from "./IsoDate"; -import { IsoDateTime } from "./IsoDateTime"; -import { Locale } from "./Locale"; - -/** - - * An ICU4X DateFormatter object capable of formatting a {@link Date `Date`} as a string, using some calendar specified at runtime in the locale. - - * See the {@link https://docs.rs/icu/latest/icu/datetime/struct.DateFormatter.html Rust documentation for `DateFormatter`} for more information. - */ +// generated by diplomat-tool +import type { DataProvider } from "./DataProvider" +import type { Date } from "./Date" +import type { DateLength } from "./DateLength" +import type { DateTime } from "./DateTime" +import type { IsoDate } from "./IsoDate" +import type { IsoDateTime } from "./IsoDateTime" +import type { Locale } from "./Locale" +import type { pointer, char } from "./diplomat-runtime.d.ts"; + + +/** An ICU4X DateFormatter object capable of formatting a [`Date`] as a string, +*using some calendar specified at runtime in the locale. +* +*See the [Rust documentation for `DateFormatter`](https://docs.rs/icu/latest/icu/datetime/struct.DateFormatter.html) for more information. +*/ export class DateFormatter { + - /** - - * Creates a new {@link DateFormatter `DateFormatter`} from locale data. - - * See the {@link https://docs.rs/icu/latest/icu/datetime/struct.DateFormatter.html#method.try_new_with_length Rust documentation for `try_new_with_length`} for more information. - * @throws {@link FFIError}<{@link Error}> - */ - static create_with_length(provider: DataProvider, locale: Locale, date_length: DateLength): DateFormatter | never; - - /** - - * Formats a {@link Date `Date`} to a string. - - * See the {@link https://docs.rs/icu/latest/icu/datetime/struct.DateFormatter.html#method.format Rust documentation for `format`} for more information. - * @throws {@link FFIError}<{@link Error}> - */ - format_date(value: Date): string | never; - - /** - - * Formats a {@link IsoDate `IsoDate`} to a string. - - * Will convert to this formatter's calendar first + get ffiValue(): pointer; - * See the {@link https://docs.rs/icu/latest/icu/datetime/struct.DateFormatter.html#method.format Rust documentation for `format`} for more information. - * @throws {@link FFIError}<{@link Error}> - */ - format_iso_date(value: IsoDate): string | never; - /** + static createWithLength(provider: DataProvider, locale: Locale, dateLength: DateLength): DateFormatter; - * Formats a {@link DateTime `DateTime`} to a string. + formatDate(value: Date): string; - * See the {@link https://docs.rs/icu/latest/icu/datetime/struct.DateFormatter.html#method.format Rust documentation for `format`} for more information. - * @throws {@link FFIError}<{@link Error}> - */ - format_datetime(value: DateTime): string | never; + formatIsoDate(value: IsoDate): string; - /** + formatDatetime(value: DateTime): string; - * Formats a {@link IsoDateTime `IsoDateTime`} to a string. + formatIsoDatetime(value: IsoDateTime): string; - * Will convert to this formatter's calendar first + - * See the {@link https://docs.rs/icu/latest/icu/datetime/struct.DateFormatter.html#method.format Rust documentation for `format`} for more information. - * @throws {@link FFIError}<{@link Error}> - */ - format_iso_datetime(value: IsoDateTime): string | never; -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/DateFormatter.mjs b/ffi/capi/bindings/js/DateFormatter.mjs index 7b0658285d4..e52ca964386 100644 --- a/ffi/capi/bindings/js/DateFormatter.mjs +++ b/ffi/capi/bindings/js/DateFormatter.mjs @@ -1,112 +1,158 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" -import { DateLength_js_to_rust, DateLength_rust_to_js } from "./DateLength.mjs" -import { Error_js_to_rust, Error_rust_to_js } from "./Error.mjs" +// generated by diplomat-tool +import { DataProvider } from "./DataProvider.mjs" +import { Date } from "./Date.mjs" +import { DateLength } from "./DateLength.mjs" +import { DateTime } from "./DateTime.mjs" +import { Error } from "./Error.mjs" +import { IsoDate } from "./IsoDate.mjs" +import { IsoDateTime } from "./IsoDateTime.mjs" +import { Locale } from "./Locale.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -const DateFormatter_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XDateFormatter_destroy(underlying); -}); +/** An ICU4X DateFormatter object capable of formatting a [`Date`] as a string, +*using some calendar specified at runtime in the locale. +* +*See the [Rust documentation for `DateFormatter`](https://docs.rs/icu/latest/icu/datetime/struct.DateFormatter.html) for more information. +*/ + +const DateFormatter_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XDateFormatter_destroy(ptr); +}); export class DateFormatter { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - DateFormatter_box_destroy_registry.register(this, underlying); + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + + constructor(ptr, selfEdge) { + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + DateFormatter_box_destroy_registry.register(this, this.#ptr); } - } - static create_with_length(arg_provider, arg_locale, arg_date_length) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XDateFormatter_create_with_length(diplomat_receive_buffer, arg_provider.underlying, arg_locale.underlying, DateLength_js_to_rust[arg_date_length]); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new DateFormatter(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = Error_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } + get ffiValue() { + return this.#ptr; + } + + + static createWithLength(provider, locale, dateLength) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XDateFormatter_create_with_length(diplomat_receive_buffer, provider.ffiValue, locale.ffiValue, dateLength.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = (() => {for (let i of Error.values) { if(i[1] === diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)) return Error[i[0]]; } return null;})(); + throw new Error('Error: ' + cause.value, { cause }); + } + return new DateFormatter(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } - format_date(arg_value) { - return diplomatRuntime.withDiplomatWrite(wasm, (write) => { - return (() => { + formatDate(value) { + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XDateFormatter_format_date(diplomat_receive_buffer, this.underlying, arg_value.underlying, write); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = {}; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = Error_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); + + const write = wasm.diplomat_buffer_write_create(0); + const result = wasm.ICU4XDateFormatter_format_date(diplomat_receive_buffer, this.ffiValue, value.ffiValue, write); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = (() => {for (let i of Error.values) { if(i[1] === diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)) return Error[i[0]]; } return null;})(); + throw new Error('Error: ' + cause.value, { cause }); + } + return diplomatRuntime.readString8(wasm, wasm.diplomat_buffer_write_get_bytes(write), wasm.diplomat_buffer_write_len(write)); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + wasm.diplomat_buffer_write_destroy(write); + } - })(); - }); - } + } - format_iso_date(arg_value) { - return diplomatRuntime.withDiplomatWrite(wasm, (write) => { - return (() => { + formatIsoDate(value) { + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XDateFormatter_format_iso_date(diplomat_receive_buffer, this.underlying, arg_value.underlying, write); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = {}; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = Error_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); + + const write = wasm.diplomat_buffer_write_create(0); + const result = wasm.ICU4XDateFormatter_format_iso_date(diplomat_receive_buffer, this.ffiValue, value.ffiValue, write); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = (() => {for (let i of Error.values) { if(i[1] === diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)) return Error[i[0]]; } return null;})(); + throw new Error('Error: ' + cause.value, { cause }); + } + return diplomatRuntime.readString8(wasm, wasm.diplomat_buffer_write_get_bytes(write), wasm.diplomat_buffer_write_len(write)); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + wasm.diplomat_buffer_write_destroy(write); + } - })(); - }); - } + } - format_datetime(arg_value) { - return diplomatRuntime.withDiplomatWrite(wasm, (write) => { - return (() => { + formatDatetime(value) { + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XDateFormatter_format_datetime(diplomat_receive_buffer, this.underlying, arg_value.underlying, write); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = {}; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = Error_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); + + const write = wasm.diplomat_buffer_write_create(0); + const result = wasm.ICU4XDateFormatter_format_datetime(diplomat_receive_buffer, this.ffiValue, value.ffiValue, write); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = (() => {for (let i of Error.values) { if(i[1] === diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)) return Error[i[0]]; } return null;})(); + throw new Error('Error: ' + cause.value, { cause }); + } + return diplomatRuntime.readString8(wasm, wasm.diplomat_buffer_write_get_bytes(write), wasm.diplomat_buffer_write_len(write)); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + wasm.diplomat_buffer_write_destroy(write); + } - })(); - }); - } + } - format_iso_datetime(arg_value) { - return diplomatRuntime.withDiplomatWrite(wasm, (write) => { - return (() => { + formatIsoDatetime(value) { + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XDateFormatter_format_iso_datetime(diplomat_receive_buffer, this.underlying, arg_value.underlying, write); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = {}; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = Error_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); + + const write = wasm.diplomat_buffer_write_create(0); + const result = wasm.ICU4XDateFormatter_format_iso_datetime(diplomat_receive_buffer, this.ffiValue, value.ffiValue, write); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = (() => {for (let i of Error.values) { if(i[1] === diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)) return Error[i[0]]; } return null;})(); + throw new Error('Error: ' + cause.value, { cause }); + } + return diplomatRuntime.readString8(wasm, wasm.diplomat_buffer_write_get_bytes(write), wasm.diplomat_buffer_write_len(write)); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + wasm.diplomat_buffer_write_destroy(write); + } - })(); - }); - } -} + } + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/DateLength.d.ts b/ffi/capi/bindings/js/DateLength.d.ts index 19d3fa42c04..428bf0c6e0e 100644 --- a/ffi/capi/bindings/js/DateLength.d.ts +++ b/ffi/capi/bindings/js/DateLength.d.ts @@ -1,19 +1,25 @@ +// generated by diplomat-tool +import type { pointer, char } from "./diplomat-runtime.d.ts"; + +// Base enumerator definition +/** See the [Rust documentation for `Date`](https://docs.rs/icu/latest/icu/datetime/options/length/enum.Date.html) for more information. +*/ +export class DateLength { + constructor(value : DateLength | string); + + get value() : string; + + get ffiValue() : number; + + static Full : DateLength; + + static Long : DateLength; + + static Medium : DateLength; + + static Short : DateLength; + + + -/** - - * See the {@link https://docs.rs/icu/latest/icu/datetime/options/length/enum.Date.html Rust documentation for `Date`} for more information. - */ -export enum DateLength { - /** - */ - Full = 'Full', - /** - */ - Long = 'Long', - /** - */ - Medium = 'Medium', - /** - */ - Short = 'Short', } \ No newline at end of file diff --git a/ffi/capi/bindings/js/DateLength.mjs b/ffi/capi/bindings/js/DateLength.mjs index af497b4bec5..7086d0d0a8b 100644 --- a/ffi/capi/bindings/js/DateLength.mjs +++ b/ffi/capi/bindings/js/DateLength.mjs @@ -1,23 +1,50 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" - -export const DateLength_js_to_rust = { - "Full": 0, - "Long": 1, - "Medium": 2, - "Short": 3, -}; - -export const DateLength_rust_to_js = { - [0]: "Full", - [1]: "Long", - [2]: "Medium", - [3]: "Short", -}; - -export const DateLength = { - "Full": "Full", - "Long": "Long", - "Medium": "Medium", - "Short": "Short", -}; +// generated by diplomat-tool +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; + +// Base enumerator definition +/** See the [Rust documentation for `Date`](https://docs.rs/icu/latest/icu/datetime/options/length/enum.Date.html) for more information. +*/ +export class DateLength { + #value = undefined; + + static values = new Map([ + ["Full", 0], + ["Long", 1], + ["Medium", 2], + ["Short", 3] + ]); + constructor(value) { + if (value instanceof DateLength) { + this.#value = value.value; + return; + } + + if (DateLength.values.has(value)) { + this.#value = value; + return; + } + + throw TypeError(value + " is not a DateLength and does not correspond to any of its enumerator values."); + } + + get value() { + return this.#value; + } + + get ffiValue() { + return DateLength.values.get(this.#value); + } + + static Full = new DateLength("Full"); + + static Long = new DateLength("Long"); + + static Medium = new DateLength("Medium"); + + static Short = new DateLength("Short"); + + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/DateTime.d.ts b/ffi/capi/bindings/js/DateTime.d.ts index 3d0a369006e..623777fa11e 100644 --- a/ffi/capi/bindings/js/DateTime.d.ts +++ b/ffi/capi/bindings/js/DateTime.d.ts @@ -1,217 +1,72 @@ -import { u8, u16, i32, u32 } from "./diplomat-runtime" -import { FFIError } from "./diplomat-runtime" -import { Calendar } from "./Calendar"; -import { CalendarError } from "./CalendarError"; -import { Date } from "./Date"; -import { IsoDateTime } from "./IsoDateTime"; -import { IsoWeekday } from "./IsoWeekday"; -import { Time } from "./Time"; -import { WeekCalculator } from "./WeekCalculator"; -import { WeekOf } from "./WeekOf"; - -/** - - * An ICU4X DateTime object capable of containing a date and time for any calendar. - - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.DateTime.html Rust documentation for `DateTime`} for more information. - */ +// generated by diplomat-tool +import type { Calendar } from "./Calendar" +import type { Date } from "./Date" +import type { IsoDateTime } from "./IsoDateTime" +import type { IsoWeekday } from "./IsoWeekday" +import type { Time } from "./Time" +import type { WeekCalculator } from "./WeekCalculator" +import type { WeekOf } from "./WeekOf" +import type { pointer, char } from "./diplomat-runtime.d.ts"; + + +/** An ICU4X DateTime object capable of containing a date and time for any calendar. +* +*See the [Rust documentation for `DateTime`](https://docs.rs/icu/latest/icu/calendar/struct.DateTime.html) for more information. +*/ export class DateTime { + - /** + get ffiValue(): pointer; - * Creates a new {@link DateTime `DateTime`} representing the ISO date and time given but in a given calendar - * See the {@link https://docs.rs/icu/latest/icu/struct.DateTime.html#method.new_from_iso Rust documentation for `new_from_iso`} for more information. - * @throws {@link FFIError}<{@link CalendarError}> - */ - static create_from_iso_in_calendar(year: i32, month: u8, day: u8, hour: u8, minute: u8, second: u8, nanosecond: u32, calendar: Calendar): DateTime | never; + static createFromIsoInCalendar(year: number, month: number, day: number, hour: number, minute: number, second: number, nanosecond: number, calendar: Calendar): DateTime; - /** + static createFromCodesInCalendar(eraCode: string, year: number, monthCode: string, day: number, hour: number, minute: number, second: number, nanosecond: number, calendar: Calendar): DateTime; - * Creates a new {@link DateTime `DateTime`} from the given codes, which are interpreted in the given calendar system + static createFromDateAndTime(date: Date, time: Time): DateTime; - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.DateTime.html#method.try_new_from_codes Rust documentation for `try_new_from_codes`} for more information. - * @throws {@link FFIError}<{@link CalendarError}> - */ - static create_from_codes_in_calendar(era_code: string, year: i32, month_code: string, day: u8, hour: u8, minute: u8, second: u8, nanosecond: u32, calendar: Calendar): DateTime | never; + get date(): Date; - /** + get time(): Time; - * Creates a new {@link DateTime `DateTime`} from an {@link Date `Date`} and {@link Time `Time`} object + toIso(): IsoDateTime; - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.DateTime.html#method.new Rust documentation for `new`} for more information. - */ - static create_from_date_and_time(date: Date, time: Time): DateTime; + toCalendar(calendar: Calendar): DateTime; - /** + get hour(): number; - * Gets a copy of the date contained in this object + get minute(): number; - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.DateTime.html#structfield.date Rust documentation for `date`} for more information. - */ - date(): Date; + get second(): number; - /** + get nanosecond(): number; - * Gets the time contained in this object + get dayOfYear(): number; - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.DateTime.html#structfield.time Rust documentation for `time`} for more information. - */ - time(): Time; + get dayOfMonth(): number; - /** + get dayOfWeek(): IsoWeekday; - * Converts this date to ISO + weekOfMonth(firstWeekday: IsoWeekday): number; - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.DateTime.html#method.to_iso Rust documentation for `to_iso`} for more information. - */ - to_iso(): IsoDateTime; + weekOfYear(calculator: WeekCalculator): WeekOf; - /** + get ordinalMonth(): number; - * Convert this datetime to one in a different calendar + get monthCode(): string; - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.DateTime.html#method.to_calendar Rust documentation for `to_calendar`} for more information. - */ - to_calendar(calendar: Calendar): DateTime; + get yearInEra(): number; - /** + get era(): string; - * Returns the hour in this time + get monthsInYear(): number; - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.Time.html#structfield.hour Rust documentation for `hour`} for more information. - */ - hour(): u8; + get daysInMonth(): number; - /** + get daysInYear(): number; - * Returns the minute in this time + get calendar(): Calendar; - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.Time.html#structfield.minute Rust documentation for `minute`} for more information. - */ - minute(): u8; + - /** - - * Returns the second in this time - - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.Time.html#structfield.second Rust documentation for `second`} for more information. - */ - second(): u8; - - /** - - * Returns the nanosecond in this time - - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.Time.html#structfield.nanosecond Rust documentation for `nanosecond`} for more information. - */ - nanosecond(): u32; - - /** - - * Returns the 1-indexed day in the year for this date - - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.day_of_year_info Rust documentation for `day_of_year_info`} for more information. - */ - day_of_year(): u16; - - /** - - * Returns the 1-indexed day in the month for this date - - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.day_of_month Rust documentation for `day_of_month`} for more information. - */ - day_of_month(): u32; - - /** - - * Returns the day in the week for this day - - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.day_of_week Rust documentation for `day_of_week`} for more information. - */ - day_of_week(): IsoWeekday; - - /** - - * Returns the week number in this month, 1-indexed, based on what is considered the first day of the week (often a locale preference). - - * `first_weekday` can be obtained via `first_weekday()` on {@link WeekCalculator `WeekCalculator`} - - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.week_of_month Rust documentation for `week_of_month`} for more information. - */ - week_of_month(first_weekday: IsoWeekday): u32; - - /** - - * Returns the week number in this year, using week data - - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.week_of_year Rust documentation for `week_of_year`} for more information. - */ - week_of_year(calculator: WeekCalculator): WeekOf; - - /** - - * Returns 1-indexed number of the month of this date in its year - - * Note that for lunar calendars this may not lead to the same month having the same ordinal month across years; use month_code if you care about month identity. - - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.month Rust documentation for `month`} for more information. - */ - ordinal_month(): u32; - - /** - - * Returns the month code for this date. Typically something like "M01", "M02", but can be more complicated for lunar calendars. - - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.month Rust documentation for `month`} for more information. - */ - month_code(): string; - - /** - - * Returns the year number in the current era for this date - - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.year Rust documentation for `year`} for more information. - */ - year_in_era(): i32; - - /** - - * Returns the era for this date, - - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.year Rust documentation for `year`} for more information. - */ - era(): string; - - /** - - * Returns the number of months in the year represented by this date - - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.months_in_year Rust documentation for `months_in_year`} for more information. - */ - months_in_year(): u8; - - /** - - * Returns the number of days in the month represented by this date - - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.days_in_month Rust documentation for `days_in_month`} for more information. - */ - days_in_month(): u8; - - /** - - * Returns the number of days in the year represented by this date - - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.days_in_year Rust documentation for `days_in_year`} for more information. - */ - days_in_year(): u16; - - /** - - * Returns the {@link Calendar `Calendar`} object backing this date - - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.calendar Rust documentation for `calendar`} for more information. - */ - calendar(): Calendar; -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/DateTime.mjs b/ffi/capi/bindings/js/DateTime.mjs index c355bc79aa5..ad5180a7095 100644 --- a/ffi/capi/bindings/js/DateTime.mjs +++ b/ffi/capi/bindings/js/DateTime.mjs @@ -1,162 +1,346 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" +// generated by diplomat-tool import { Calendar } from "./Calendar.mjs" -import { CalendarError_js_to_rust, CalendarError_rust_to_js } from "./CalendarError.mjs" +import { CalendarError } from "./CalendarError.mjs" import { Date } from "./Date.mjs" import { IsoDateTime } from "./IsoDateTime.mjs" -import { IsoWeekday_js_to_rust, IsoWeekday_rust_to_js } from "./IsoWeekday.mjs" +import { IsoWeekday } from "./IsoWeekday.mjs" import { Time } from "./Time.mjs" +import { WeekCalculator } from "./WeekCalculator.mjs" import { WeekOf } from "./WeekOf.mjs" -import { WeekRelativeUnit_js_to_rust, WeekRelativeUnit_rust_to_js } from "./WeekRelativeUnit.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -const DateTime_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XDateTime_destroy(underlying); -}); +/** An ICU4X DateTime object capable of containing a date and time for any calendar. +* +*See the [Rust documentation for `DateTime`](https://docs.rs/icu/latest/icu/calendar/struct.DateTime.html) for more information. +*/ + +const DateTime_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XDateTime_destroy(ptr); +}); export class DateTime { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - DateTime_box_destroy_registry.register(this, underlying); - } - } - - static create_from_iso_in_calendar(arg_year, arg_month, arg_day, arg_hour, arg_minute, arg_second, arg_nanosecond, arg_calendar) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XDateTime_create_from_iso_in_calendar(diplomat_receive_buffer, arg_year, arg_month, arg_day, arg_hour, arg_minute, arg_second, arg_nanosecond, arg_calendar.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new DateTime(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = CalendarError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static create_from_codes_in_calendar(arg_era_code, arg_year, arg_month_code, arg_day, arg_hour, arg_minute, arg_second, arg_nanosecond, arg_calendar) { - const buf_arg_era_code = diplomatRuntime.DiplomatBuf.str8(wasm, arg_era_code); - const buf_arg_month_code = diplomatRuntime.DiplomatBuf.str8(wasm, arg_month_code); - const diplomat_out = (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XDateTime_create_from_codes_in_calendar(diplomat_receive_buffer, buf_arg_era_code.ptr, buf_arg_era_code.size, arg_year, buf_arg_month_code.ptr, buf_arg_month_code.size, arg_day, arg_hour, arg_minute, arg_second, arg_nanosecond, arg_calendar.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new DateTime(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = CalendarError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - buf_arg_era_code.free(); - buf_arg_month_code.free(); - return diplomat_out; - } - - static create_from_date_and_time(arg_date, arg_time) { - return new DateTime(wasm.ICU4XDateTime_create_from_date_and_time(arg_date.underlying, arg_time.underlying), true, []); - } - - date() { - return new Date(wasm.ICU4XDateTime_date(this.underlying), true, []); - } - - time() { - return new Time(wasm.ICU4XDateTime_time(this.underlying), true, []); - } - - to_iso() { - return new IsoDateTime(wasm.ICU4XDateTime_to_iso(this.underlying), true, []); - } - - to_calendar(arg_calendar) { - return new DateTime(wasm.ICU4XDateTime_to_calendar(this.underlying, arg_calendar.underlying), true, []); - } - - hour() { - return wasm.ICU4XDateTime_hour(this.underlying); - } - - minute() { - return wasm.ICU4XDateTime_minute(this.underlying); - } - - second() { - return wasm.ICU4XDateTime_second(this.underlying); - } - - nanosecond() { - return wasm.ICU4XDateTime_nanosecond(this.underlying); - } - - day_of_year() { - return wasm.ICU4XDateTime_day_of_year(this.underlying); - } - - day_of_month() { - return wasm.ICU4XDateTime_day_of_month(this.underlying); - } - - day_of_week() { - return IsoWeekday_rust_to_js[wasm.ICU4XDateTime_day_of_week(this.underlying)]; - } - - week_of_month(arg_first_weekday) { - return wasm.ICU4XDateTime_week_of_month(this.underlying, IsoWeekday_js_to_rust[arg_first_weekday]); - } - - week_of_year(arg_calculator) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(8, 4); - wasm.ICU4XDateTime_week_of_year(diplomat_receive_buffer, this.underlying, arg_calculator.underlying); - const out = new WeekOf(diplomat_receive_buffer); - wasm.diplomat_free(diplomat_receive_buffer, 8, 4); - return out; - })(); - } - - ordinal_month() { - return wasm.ICU4XDateTime_ordinal_month(this.underlying); - } - - month_code() { - return diplomatRuntime.withDiplomatWrite(wasm, (write) => { - return wasm.ICU4XDateTime_month_code(this.underlying, write); - }); - } - - year_in_era() { - return wasm.ICU4XDateTime_year_in_era(this.underlying); - } - - era() { - return diplomatRuntime.withDiplomatWrite(wasm, (write) => { - return wasm.ICU4XDateTime_era(this.underlying, write); - }); - } - - months_in_year() { - return wasm.ICU4XDateTime_months_in_year(this.underlying); - } - - days_in_month() { - return wasm.ICU4XDateTime_days_in_month(this.underlying); - } - - days_in_year() { - return wasm.ICU4XDateTime_days_in_year(this.underlying); - } - - calendar() { - return new Calendar(wasm.ICU4XDateTime_calendar(this.underlying), true, []); - } -} + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + + constructor(ptr, selfEdge) { + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + DateTime_box_destroy_registry.register(this, this.#ptr); + } + + get ffiValue() { + return this.#ptr; + } + + + static createFromIsoInCalendar(year, month, day, hour, minute, second, nanosecond, calendar) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XDateTime_create_from_iso_in_calendar(diplomat_receive_buffer, year, month, day, hour, minute, second, nanosecond, calendar.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = CalendarError[Array.from(CalendarError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('CalendarError: ' + cause.value, { cause }); + } + return new DateTime(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static createFromCodesInCalendar(eraCode, year, monthCode, day, hour, minute, second, nanosecond, calendar) { + + const eraCodeSlice = diplomatRuntime.DiplomatBuf.str8(wasm, eraCode); + + const monthCodeSlice = diplomatRuntime.DiplomatBuf.str8(wasm, monthCode); + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XDateTime_create_from_codes_in_calendar(diplomat_receive_buffer, eraCodeSlice.ptr, eraCodeSlice.size, year, monthCodeSlice.ptr, monthCodeSlice.size, day, hour, minute, second, nanosecond, calendar.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = CalendarError[Array.from(CalendarError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('CalendarError: ' + cause.value, { cause }); + } + return new DateTime(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + eraCodeSlice.free(); + + monthCodeSlice.free(); + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static createFromDateAndTime(date, time) { + const result = wasm.ICU4XDateTime_create_from_date_and_time(date.ffiValue, time.ffiValue); + + try { + + return new DateTime(result, []); + } finally { + + } + } + + get date() { + const result = wasm.ICU4XDateTime_date(this.ffiValue); + + try { + + return new Date(result, []); + } finally { + + } + } + + get time() { + const result = wasm.ICU4XDateTime_time(this.ffiValue); + + try { + + return new Time(result, []); + } finally { + + } + } + + toIso() { + const result = wasm.ICU4XDateTime_to_iso(this.ffiValue); + + try { + + return new IsoDateTime(result, []); + } finally { + + } + } + + toCalendar(calendar) { + const result = wasm.ICU4XDateTime_to_calendar(this.ffiValue, calendar.ffiValue); + + try { + + return new DateTime(result, []); + } finally { + + } + } + + get hour() { + const result = wasm.ICU4XDateTime_hour(this.ffiValue); + + try { + + return result; + } finally { + + } + } + + get minute() { + const result = wasm.ICU4XDateTime_minute(this.ffiValue); + + try { + + return result; + } finally { + + } + } + + get second() { + const result = wasm.ICU4XDateTime_second(this.ffiValue); + + try { + + return result; + } finally { + + } + } + + get nanosecond() { + const result = wasm.ICU4XDateTime_nanosecond(this.ffiValue); + + try { + + return result; + } finally { + + } + } + + get dayOfYear() { + const result = wasm.ICU4XDateTime_day_of_year(this.ffiValue); + + try { + + return result; + } finally { + + } + } + + get dayOfMonth() { + const result = wasm.ICU4XDateTime_day_of_month(this.ffiValue); + + try { + + return result; + } finally { + + } + } + + get dayOfWeek() { + const result = wasm.ICU4XDateTime_day_of_week(this.ffiValue); + + try { + + return (() => {for (let i of IsoWeekday.values) { if(i[1] === result) return IsoWeekday[i[0]]; } return null;})(); + } finally { + + } + } + + weekOfMonth(firstWeekday) { + const result = wasm.ICU4XDateTime_week_of_month(this.ffiValue, firstWeekday.ffiValue); + + try { + + return result; + } finally { + + } + } + + weekOfYear(calculator) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(8, 4); + const result = wasm.ICU4XDateTime_week_of_year(diplomat_receive_buffer, this.ffiValue, calculator.ffiValue); + + try { + + return new WeekOf(diplomat_receive_buffer); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 8, 4); + + } + } + + get ordinalMonth() { + const result = wasm.ICU4XDateTime_ordinal_month(this.ffiValue); + + try { + + return result; + } finally { + + } + } + + get monthCode() { + + const write = wasm.diplomat_buffer_write_create(0); + wasm.ICU4XDateTime_month_code(this.ffiValue, write); + + try { + + return diplomatRuntime.readString8(wasm, wasm.diplomat_buffer_write_get_bytes(write), wasm.diplomat_buffer_write_len(write)); + } finally { + + wasm.diplomat_buffer_write_destroy(write); + + } + } + + get yearInEra() { + const result = wasm.ICU4XDateTime_year_in_era(this.ffiValue); + + try { + + return result; + } finally { + + } + } + + get era() { + + const write = wasm.diplomat_buffer_write_create(0); + wasm.ICU4XDateTime_era(this.ffiValue, write); + + try { + + return diplomatRuntime.readString8(wasm, wasm.diplomat_buffer_write_get_bytes(write), wasm.diplomat_buffer_write_len(write)); + } finally { + + wasm.diplomat_buffer_write_destroy(write); + + } + } + + get monthsInYear() { + const result = wasm.ICU4XDateTime_months_in_year(this.ffiValue); + + try { + + return result; + } finally { + + } + } + + get daysInMonth() { + const result = wasm.ICU4XDateTime_days_in_month(this.ffiValue); + + try { + + return result; + } finally { + + } + } + + get daysInYear() { + const result = wasm.ICU4XDateTime_days_in_year(this.ffiValue); + + try { + + return result; + } finally { + + } + } + + get calendar() { + const result = wasm.ICU4XDateTime_calendar(this.ffiValue); + + try { + + return new Calendar(result, []); + } finally { + + } + } + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/DateTimeFormatter.d.ts b/ffi/capi/bindings/js/DateTimeFormatter.d.ts index a15dabfbaba..cadf260f18b 100644 --- a/ffi/capi/bindings/js/DateTimeFormatter.d.ts +++ b/ffi/capi/bindings/js/DateTimeFormatter.d.ts @@ -1,46 +1,30 @@ -import { FFIError } from "./diplomat-runtime" -import { DataProvider } from "./DataProvider"; -import { DateLength } from "./DateLength"; -import { DateTime } from "./DateTime"; -import { Error } from "./Error"; -import { IsoDateTime } from "./IsoDateTime"; -import { Locale } from "./Locale"; -import { TimeLength } from "./TimeLength"; - -/** - - * An ICU4X DateFormatter object capable of formatting a {@link DateTime `DateTime`} as a string, using some calendar specified at runtime in the locale. - - * See the {@link https://docs.rs/icu/latest/icu/datetime/struct.DateTimeFormatter.html Rust documentation for `DateTimeFormatter`} for more information. - */ +// generated by diplomat-tool +import type { DataProvider } from "./DataProvider" +import type { DateLength } from "./DateLength" +import type { DateTime } from "./DateTime" +import type { IsoDateTime } from "./IsoDateTime" +import type { Locale } from "./Locale" +import type { TimeLength } from "./TimeLength" +import type { pointer, char } from "./diplomat-runtime.d.ts"; + + +/** An ICU4X DateFormatter object capable of formatting a [`DateTime`] as a string, +*using some calendar specified at runtime in the locale. +* +*See the [Rust documentation for `DateTimeFormatter`](https://docs.rs/icu/latest/icu/datetime/struct.DateTimeFormatter.html) for more information. +*/ export class DateTimeFormatter { + - /** - - * Creates a new {@link DateTimeFormatter `DateTimeFormatter`} from locale data. - - * See the {@link https://docs.rs/icu/latest/icu/datetime/struct.DateTimeFormatter.html#method.try_new Rust documentation for `try_new`} for more information. - * @throws {@link FFIError}<{@link Error}> - */ - static create_with_lengths(provider: DataProvider, locale: Locale, date_length: DateLength, time_length: TimeLength): DateTimeFormatter | never; - - /** + get ffiValue(): pointer; - * Formats a {@link DateTime `DateTime`} to a string. - * See the {@link https://docs.rs/icu/latest/icu/datetime/struct.DateTimeFormatter.html#method.format Rust documentation for `format`} for more information. - * @throws {@link FFIError}<{@link Error}> - */ - format_datetime(value: DateTime): string | never; + static createWithLengths(provider: DataProvider, locale: Locale, dateLength: DateLength, timeLength: TimeLength): DateTimeFormatter; - /** + formatDatetime(value: DateTime): string; - * Formats a {@link IsoDateTime `IsoDateTime`} to a string. + formatIsoDatetime(value: IsoDateTime): string; - * Will convert to this formatter's calendar first + - * See the {@link https://docs.rs/icu/latest/icu/datetime/struct.DateTimeFormatter.html#method.format Rust documentation for `format`} for more information. - * @throws {@link FFIError}<{@link Error}> - */ - format_iso_datetime(value: IsoDateTime): string | never; -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/DateTimeFormatter.mjs b/ffi/capi/bindings/js/DateTimeFormatter.mjs index b5d00bf966a..1fb5e0a5130 100644 --- a/ffi/capi/bindings/js/DateTimeFormatter.mjs +++ b/ffi/capi/bindings/js/DateTimeFormatter.mjs @@ -1,75 +1,111 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" -import { DateLength_js_to_rust, DateLength_rust_to_js } from "./DateLength.mjs" -import { Error_js_to_rust, Error_rust_to_js } from "./Error.mjs" -import { TimeLength_js_to_rust, TimeLength_rust_to_js } from "./TimeLength.mjs" +// generated by diplomat-tool +import { DataProvider } from "./DataProvider.mjs" +import { DateLength } from "./DateLength.mjs" +import { DateTime } from "./DateTime.mjs" +import { Error } from "./Error.mjs" +import { IsoDateTime } from "./IsoDateTime.mjs" +import { Locale } from "./Locale.mjs" +import { TimeLength } from "./TimeLength.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -const DateTimeFormatter_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XDateTimeFormatter_destroy(underlying); -}); +/** An ICU4X DateFormatter object capable of formatting a [`DateTime`] as a string, +*using some calendar specified at runtime in the locale. +* +*See the [Rust documentation for `DateTimeFormatter`](https://docs.rs/icu/latest/icu/datetime/struct.DateTimeFormatter.html) for more information. +*/ + +const DateTimeFormatter_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XDateTimeFormatter_destroy(ptr); +}); export class DateTimeFormatter { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - DateTimeFormatter_box_destroy_registry.register(this, underlying); + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + + constructor(ptr, selfEdge) { + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + DateTimeFormatter_box_destroy_registry.register(this, this.#ptr); } - } - static create_with_lengths(arg_provider, arg_locale, arg_date_length, arg_time_length) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XDateTimeFormatter_create_with_lengths(diplomat_receive_buffer, arg_provider.underlying, arg_locale.underlying, DateLength_js_to_rust[arg_date_length], TimeLength_js_to_rust[arg_time_length]); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new DateTimeFormatter(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = Error_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } + get ffiValue() { + return this.#ptr; + } + + + static createWithLengths(provider, locale, dateLength, timeLength) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XDateTimeFormatter_create_with_lengths(diplomat_receive_buffer, provider.ffiValue, locale.ffiValue, dateLength.ffiValue, timeLength.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = (() => {for (let i of Error.values) { if(i[1] === diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)) return Error[i[0]]; } return null;})(); + throw new Error('Error: ' + cause.value, { cause }); + } + return new DateTimeFormatter(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } - format_datetime(arg_value) { - return diplomatRuntime.withDiplomatWrite(wasm, (write) => { - return (() => { + formatDatetime(value) { + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XDateTimeFormatter_format_datetime(diplomat_receive_buffer, this.underlying, arg_value.underlying, write); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = {}; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = Error_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); + + const write = wasm.diplomat_buffer_write_create(0); + const result = wasm.ICU4XDateTimeFormatter_format_datetime(diplomat_receive_buffer, this.ffiValue, value.ffiValue, write); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = (() => {for (let i of Error.values) { if(i[1] === diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)) return Error[i[0]]; } return null;})(); + throw new Error('Error: ' + cause.value, { cause }); + } + return diplomatRuntime.readString8(wasm, wasm.diplomat_buffer_write_get_bytes(write), wasm.diplomat_buffer_write_len(write)); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + wasm.diplomat_buffer_write_destroy(write); + } - })(); - }); - } + } - format_iso_datetime(arg_value) { - return diplomatRuntime.withDiplomatWrite(wasm, (write) => { - return (() => { + formatIsoDatetime(value) { + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XDateTimeFormatter_format_iso_datetime(diplomat_receive_buffer, this.underlying, arg_value.underlying, write); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = {}; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = Error_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); + + const write = wasm.diplomat_buffer_write_create(0); + const result = wasm.ICU4XDateTimeFormatter_format_iso_datetime(diplomat_receive_buffer, this.ffiValue, value.ffiValue, write); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = (() => {for (let i of Error.values) { if(i[1] === diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)) return Error[i[0]]; } return null;})(); + throw new Error('Error: ' + cause.value, { cause }); + } + return diplomatRuntime.readString8(wasm, wasm.diplomat_buffer_write_get_bytes(write), wasm.diplomat_buffer_write_len(write)); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + wasm.diplomat_buffer_write_destroy(write); + } - })(); - }); - } -} + } + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/Decomposed.d.ts b/ffi/capi/bindings/js/Decomposed.d.ts index a538945be0d..b544f90e942 100644 --- a/ffi/capi/bindings/js/Decomposed.d.ts +++ b/ffi/capi/bindings/js/Decomposed.d.ts @@ -1,12 +1,19 @@ -import { char } from "./diplomat-runtime" +// generated by diplomat-tool +import type { pointer, char } from "./diplomat-runtime.d.ts"; -/** - * The outcome of non-recursive canonical decomposition of a character. `second` will be NUL when the decomposition expands to a single character (which may or may not be the original one) - - * See the {@link https://docs.rs/icu/latest/icu/normalizer/properties/enum.Decomposed.html Rust documentation for `Decomposed`} for more information. - */ +/** The outcome of non-recursive canonical decomposition of a character. +*`second` will be NUL when the decomposition expands to a single character +*(which may or may not be the original one) +* +*See the [Rust documentation for `Decomposed`](https://docs.rs/icu/latest/icu/normalizer/properties/enum.Decomposed.html) for more information. +*/ export class Decomposed { - first: char; - second: char; -} + get first() : char; + + get second() : char; + + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/Decomposed.mjs b/ffi/capi/bindings/js/Decomposed.mjs index cba085392d6..f4a8b77f102 100644 --- a/ffi/capi/bindings/js/Decomposed.mjs +++ b/ffi/capi/bindings/js/Decomposed.mjs @@ -1,9 +1,53 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" +// generated by diplomat-tool +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; + +/** The outcome of non-recursive canonical decomposition of a character. +*`second` will be NUL when the decomposition expands to a single character +*(which may or may not be the original one) +* +*See the [Rust documentation for `Decomposed`](https://docs.rs/icu/latest/icu/normalizer/properties/enum.Decomposed.html) for more information. +*/ export class Decomposed { - constructor(underlying) { - this.first = String.fromCharCode((new Uint32Array(wasm.memory.buffer, underlying, 1))[0]); - this.second = String.fromCharCode((new Uint32Array(wasm.memory.buffer, underlying + 4, 1))[0]); - } -} + #first; + get first() { + return this.#first; + } + + #second; + get second() { + return this.#second; + } + + + // Return this struct in FFI function friendly format. + // Returns an array that can be expanded with spread syntax (...) + + _intoFFI( + slice_cleanup_callbacks, + appendArrayMap + ) { + return [diplomatRuntime.extractCodePoint(this.#first, 'this.#first'), diplomatRuntime.extractCodePoint(this.#second, 'this.#second')] + } + + // 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. + _fromFFI(ptr) { + const firstDeref = String.fromCharCode((new Uint32Array(wasm.memory.buffer, ptr, 1))[0]); + this.#first = firstDeref; + const secondDeref = String.fromCharCode((new Uint32Array(wasm.memory.buffer, ptr + 4, 1))[0]); + this.#second = secondDeref; + + return this; + } + // This is an out struct. You need to call other methods to be able to get this struct. + constructor(ptr) { + this._fromFFI(ptr); + } + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/DecomposingNormalizer.d.ts b/ffi/capi/bindings/js/DecomposingNormalizer.d.ts index def1e19b688..7586846dbd2 100644 --- a/ffi/capi/bindings/js/DecomposingNormalizer.d.ts +++ b/ffi/capi/bindings/js/DecomposingNormalizer.d.ts @@ -1,75 +1,30 @@ -import { usize } from "./diplomat-runtime" -import { FFIError } from "./diplomat-runtime" -import { DataError } from "./DataError"; -import { DataProvider } from "./DataProvider"; +// generated by diplomat-tool +import type { DataProvider } from "./DataProvider" +import type { pointer, char } from "./diplomat-runtime.d.ts"; -/** - * See the {@link https://docs.rs/icu/latest/icu/normalizer/struct.DecomposingNormalizer.html Rust documentation for `DecomposingNormalizer`} for more information. - */ +/** See the [Rust documentation for `DecomposingNormalizer`](https://docs.rs/icu/latest/icu/normalizer/struct.DecomposingNormalizer.html) for more information. +*/ export class DecomposingNormalizer { + - /** + get ffiValue(): pointer; - * Construct a new DecomposingNormalizer instance for NFC - * See the {@link https://docs.rs/icu/latest/icu/normalizer/struct.DecomposingNormalizer.html#method.new_nfd Rust documentation for `new_nfd`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static create_nfd(provider: DataProvider): DecomposingNormalizer | never; + static createNfd(provider: DataProvider): DecomposingNormalizer; - /** + static createNfkd(provider: DataProvider): DecomposingNormalizer; - * Construct a new DecomposingNormalizer instance for NFKC + normalize(s: string): string; - * See the {@link https://docs.rs/icu/latest/icu/normalizer/struct.DecomposingNormalizer.html#method.new_nfkd Rust documentation for `new_nfkd`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static create_nfkd(provider: DataProvider): DecomposingNormalizer | never; + isNormalized(s: string): boolean; - /** + isNormalizedUtf16(s: string): boolean; - * Normalize a string + isNormalizedUpTo(s: string): number; - * Ill-formed input is treated as if errors had been replaced with REPLACEMENT CHARACTERs according to the WHATWG Encoding Standard. + isNormalizedUtf16UpTo(s: string): number; - * See the {@link https://docs.rs/icu/latest/icu/normalizer/struct.DecomposingNormalizer.html#method.normalize_utf8 Rust documentation for `normalize_utf8`} for more information. - */ - normalize(s: string): string; + - /** - - * Check if a string is normalized - - * Ill-formed input is treated as if errors had been replaced with REPLACEMENT CHARACTERs according to the WHATWG Encoding Standard. - - * See the {@link https://docs.rs/icu/latest/icu/normalizer/struct.DecomposingNormalizer.html#method.is_normalized_utf8 Rust documentation for `is_normalized_utf8`} for more information. - */ - is_normalized(s: string): boolean; - - /** - - * Check if a string is normalized - - * Ill-formed input is treated as if errors had been replaced with REPLACEMENT CHARACTERs according to the WHATWG Encoding Standard. - - * See the {@link https://docs.rs/icu/latest/icu/normalizer/struct.DecomposingNormalizer.html#method.is_normalized_utf16 Rust documentation for `is_normalized_utf16`} for more information. - */ - is_normalized_utf16(s: string): boolean; - - /** - - * Return the index a slice of potentially-invalid UTF-8 is normalized up to - - * See the {@link https://docs.rs/icu/latest/icu/normalizer/struct.DecomposingNormalizer.html#method.is_normalized_utf8_up_to Rust documentation for `is_normalized_utf8_up_to`} for more information. - */ - is_normalized_up_to(s: string): usize; - - /** - - * Return the index a slice of potentially-invalid UTF-8 is normalized up to - - * See the {@link https://docs.rs/icu/latest/icu/normalizer/struct.DecomposingNormalizer.html#method.is_normalized_utf16_up_to Rust documentation for `is_normalized_utf16_up_to`} for more information. - */ - is_normalized_utf16_up_to(s: string): usize; -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/DecomposingNormalizer.mjs b/ffi/capi/bindings/js/DecomposingNormalizer.mjs index 5810b22e7eb..c3065245439 100644 --- a/ffi/capi/bindings/js/DecomposingNormalizer.mjs +++ b/ffi/capi/bindings/js/DecomposingNormalizer.mjs @@ -1,89 +1,155 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" -import { DataError_js_to_rust, DataError_rust_to_js } from "./DataError.mjs" +// generated by diplomat-tool +import { DataError } from "./DataError.mjs" +import { DataProvider } from "./DataProvider.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -const DecomposingNormalizer_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XDecomposingNormalizer_destroy(underlying); -}); +/** See the [Rust documentation for `DecomposingNormalizer`](https://docs.rs/icu/latest/icu/normalizer/struct.DecomposingNormalizer.html) for more information. +*/ + +const DecomposingNormalizer_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XDecomposingNormalizer_destroy(ptr); +}); export class DecomposingNormalizer { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - DecomposingNormalizer_box_destroy_registry.register(this, underlying); + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + + constructor(ptr, selfEdge) { + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + DecomposingNormalizer_box_destroy_registry.register(this, this.#ptr); + } + + get ffiValue() { + return this.#ptr; + } + + + static createNfd(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XDecomposingNormalizer_create_nfd(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new DecomposingNormalizer(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static createNfkd(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XDecomposingNormalizer_create_nfkd(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new DecomposingNormalizer(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } } - } - static create_nfd(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XDecomposingNormalizer_create_nfd(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new DecomposingNormalizer(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } + normalize(s) { + + const sSlice = diplomatRuntime.DiplomatBuf.str8(wasm, s); + + const write = wasm.diplomat_buffer_write_create(0); + wasm.ICU4XDecomposingNormalizer_normalize(this.ffiValue, sSlice.ptr, sSlice.size, write); + + try { + + return diplomatRuntime.readString8(wasm, wasm.diplomat_buffer_write_get_bytes(write), wasm.diplomat_buffer_write_len(write)); + } finally { + + sSlice.free(); + + wasm.diplomat_buffer_write_destroy(write); + + } + } - static create_nfkd(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XDecomposingNormalizer_create_nfkd(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new DecomposingNormalizer(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } + isNormalized(s) { + + const sSlice = diplomatRuntime.DiplomatBuf.str8(wasm, s); + const result = wasm.ICU4XDecomposingNormalizer_is_normalized(this.ffiValue, sSlice.ptr, sSlice.size); + + try { + + return result; + } finally { + + sSlice.free(); + + } + } - normalize(arg_s) { - const buf_arg_s = diplomatRuntime.DiplomatBuf.str8(wasm, arg_s); - const diplomat_out = diplomatRuntime.withDiplomatWrite(wasm, (write) => { - return wasm.ICU4XDecomposingNormalizer_normalize(this.underlying, buf_arg_s.ptr, buf_arg_s.size, write); - }); - buf_arg_s.free(); - return diplomat_out; - } + isNormalizedUtf16(s) { + + const sSlice = diplomatRuntime.DiplomatBuf.str16(wasm, s); + const result = wasm.ICU4XDecomposingNormalizer_is_normalized_utf16(this.ffiValue, sSlice.ptr, sSlice.size); + + try { + + return result; + } finally { + + sSlice.free(); + + } + } - is_normalized(arg_s) { - const buf_arg_s = diplomatRuntime.DiplomatBuf.str8(wasm, arg_s); - const diplomat_out = wasm.ICU4XDecomposingNormalizer_is_normalized(this.underlying, buf_arg_s.ptr, buf_arg_s.size); - buf_arg_s.free(); - return diplomat_out; - } + isNormalizedUpTo(s) { + + const sSlice = diplomatRuntime.DiplomatBuf.str8(wasm, s); + const result = wasm.ICU4XDecomposingNormalizer_is_normalized_up_to(this.ffiValue, sSlice.ptr, sSlice.size); + + try { + + return result; + } finally { + + sSlice.free(); + + } + } - is_normalized_utf16(arg_s) { - const buf_arg_s = diplomatRuntime.DiplomatBuf.str16(wasm, arg_s); - const diplomat_out = wasm.ICU4XDecomposingNormalizer_is_normalized_utf16(this.underlying, buf_arg_s.ptr, buf_arg_s.size); - buf_arg_s.free(); - return diplomat_out; - } + isNormalizedUtf16UpTo(s) { + + const sSlice = diplomatRuntime.DiplomatBuf.str16(wasm, s); + const result = wasm.ICU4XDecomposingNormalizer_is_normalized_utf16_up_to(this.ffiValue, sSlice.ptr, sSlice.size); + + try { + + return result; + } finally { + + sSlice.free(); + + } + } - is_normalized_up_to(arg_s) { - const buf_arg_s = diplomatRuntime.DiplomatBuf.str8(wasm, arg_s); - const diplomat_out = wasm.ICU4XDecomposingNormalizer_is_normalized_up_to(this.underlying, buf_arg_s.ptr, buf_arg_s.size); - buf_arg_s.free(); - return diplomat_out; - } + - is_normalized_utf16_up_to(arg_s) { - const buf_arg_s = diplomatRuntime.DiplomatBuf.str16(wasm, arg_s); - const diplomat_out = wasm.ICU4XDecomposingNormalizer_is_normalized_utf16_up_to(this.underlying, buf_arg_s.ptr, buf_arg_s.size); - buf_arg_s.free(); - return diplomat_out; - } -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/DisplayNamesFallback.d.ts b/ffi/capi/bindings/js/DisplayNamesFallback.d.ts index 3d70eabe3bd..d774106a78a 100644 --- a/ffi/capi/bindings/js/DisplayNamesFallback.d.ts +++ b/ffi/capi/bindings/js/DisplayNamesFallback.d.ts @@ -1,13 +1,21 @@ +// generated by diplomat-tool +import type { pointer, char } from "./diplomat-runtime.d.ts"; + +// Base enumerator definition +/** See the [Rust documentation for `Fallback`](https://docs.rs/icu/latest/icu/displaynames/options/enum.Fallback.html) for more information. +*/ +export class DisplayNamesFallback { + constructor(value : DisplayNamesFallback | string); + + get value() : string; + + get ffiValue() : number; + + static Code : DisplayNamesFallback; + + static None : DisplayNamesFallback; + + + -/** - - * See the {@link https://docs.rs/icu/latest/icu/displaynames/options/enum.Fallback.html Rust documentation for `Fallback`} for more information. - */ -export enum DisplayNamesFallback { - /** - */ - Code = 'Code', - /** - */ - None = 'None', } \ No newline at end of file diff --git a/ffi/capi/bindings/js/DisplayNamesFallback.mjs b/ffi/capi/bindings/js/DisplayNamesFallback.mjs index 9b251e37ce4..dfb7487dd80 100644 --- a/ffi/capi/bindings/js/DisplayNamesFallback.mjs +++ b/ffi/capi/bindings/js/DisplayNamesFallback.mjs @@ -1,17 +1,44 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" - -export const DisplayNamesFallback_js_to_rust = { - "Code": 0, - "None": 1, -}; - -export const DisplayNamesFallback_rust_to_js = { - [0]: "Code", - [1]: "None", -}; - -export const DisplayNamesFallback = { - "Code": "Code", - "None": "None", -}; +// generated by diplomat-tool +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; + +// Base enumerator definition +/** See the [Rust documentation for `Fallback`](https://docs.rs/icu/latest/icu/displaynames/options/enum.Fallback.html) for more information. +*/ +export class DisplayNamesFallback { + #value = undefined; + + static values = new Map([ + ["Code", 0], + ["None", 1] + ]); + constructor(value) { + if (value instanceof DisplayNamesFallback) { + this.#value = value.value; + return; + } + + if (DisplayNamesFallback.values.has(value)) { + this.#value = value; + return; + } + + throw TypeError(value + " is not a DisplayNamesFallback and does not correspond to any of its enumerator values."); + } + + get value() { + return this.#value; + } + + get ffiValue() { + return DisplayNamesFallback.values.get(this.#value); + } + + static Code = new DisplayNamesFallback("Code"); + + static None = new DisplayNamesFallback("None"); + + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/DisplayNamesOptions.d.ts b/ffi/capi/bindings/js/DisplayNamesOptions.d.ts new file mode 100644 index 00000000000..02f59b50015 --- /dev/null +++ b/ffi/capi/bindings/js/DisplayNamesOptions.d.ts @@ -0,0 +1,20 @@ +// generated by diplomat-tool +import type { DisplayNamesFallback } from "./DisplayNamesFallback" +import type { DisplayNamesStyle } from "./DisplayNamesStyle" +import type { LanguageDisplay } from "./LanguageDisplay" +import type { pointer, char } from "./diplomat-runtime.d.ts"; + + +/** See the [Rust documentation for `DisplayNamesOptions`](https://docs.rs/icu/latest/icu/displaynames/options/struct.DisplayNamesOptions.html) for more information. +*/ +export class DisplayNamesOptions { + get style() : DisplayNamesStyle; + set style(value: DisplayNamesStyle); + get fallback() : DisplayNamesFallback; + set fallback(value: DisplayNamesFallback); + get languageDisplay() : LanguageDisplay; + set languageDisplay(value: LanguageDisplay); + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/DisplayNamesOptions.mjs b/ffi/capi/bindings/js/DisplayNamesOptions.mjs new file mode 100644 index 00000000000..e55bc179218 --- /dev/null +++ b/ffi/capi/bindings/js/DisplayNamesOptions.mjs @@ -0,0 +1,61 @@ +// generated by diplomat-tool +import { DisplayNamesFallback } from "./DisplayNamesFallback.mjs" +import { DisplayNamesStyle } from "./DisplayNamesStyle.mjs" +import { LanguageDisplay } from "./LanguageDisplay.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; + + +/** See the [Rust documentation for `DisplayNamesOptions`](https://docs.rs/icu/latest/icu/displaynames/options/struct.DisplayNamesOptions.html) for more information. +*/ +export class DisplayNamesOptions { + #style; + get style() { + return this.#style; + } + set style(value) { + this.#style = value; + } + #fallback; + get fallback() { + return this.#fallback; + } + set fallback(value) { + this.#fallback = value; + } + #languageDisplay; + get languageDisplay() { + return this.#languageDisplay; + } + set languageDisplay(value) { + this.#languageDisplay = value; + } + + // Return this struct in FFI function friendly format. + // Returns an array that can be expanded with spread syntax (...) + + _intoFFI( + slice_cleanup_callbacks, + appendArrayMap + ) { + return [this.#style.ffiValue, this.#fallback.ffiValue, this.#languageDisplay.ffiValue] + } + + // 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. + _fromFFI(ptr) { + const styleDeref = diplomatRuntime.enumDiscriminant(wasm, ptr); + this.#style = DisplayNamesStyle[Array.from(DisplayNamesStyle.values.keys())[styleDeref]]; + const fallbackDeref = diplomatRuntime.enumDiscriminant(wasm, ptr + 4); + this.#fallback = DisplayNamesFallback[Array.from(DisplayNamesFallback.values.keys())[fallbackDeref]]; + const languageDisplayDeref = diplomatRuntime.enumDiscriminant(wasm, ptr + 8); + this.#languageDisplay = LanguageDisplay[Array.from(LanguageDisplay.values.keys())[languageDisplayDeref]]; + + return this; + } + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/DisplayNamesOptionsV1.d.ts b/ffi/capi/bindings/js/DisplayNamesOptionsV1.d.ts deleted file mode 100644 index 837c0212cf5..00000000000 --- a/ffi/capi/bindings/js/DisplayNamesOptionsV1.d.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { DisplayNamesFallback } from "./DisplayNamesFallback"; -import { DisplayNamesStyle } from "./DisplayNamesStyle"; -import { LanguageDisplay } from "./LanguageDisplay"; - -/** - - * See the {@link https://docs.rs/icu/latest/icu/displaynames/options/struct.DisplayNamesOptions.html Rust documentation for `DisplayNamesOptions`} for more information. - */ -export class DisplayNamesOptionsV1 { - style: DisplayNamesStyle; - fallback: DisplayNamesFallback; - language_display: LanguageDisplay; -} diff --git a/ffi/capi/bindings/js/DisplayNamesOptionsV1.mjs b/ffi/capi/bindings/js/DisplayNamesOptionsV1.mjs deleted file mode 100644 index 31da314e03c..00000000000 --- a/ffi/capi/bindings/js/DisplayNamesOptionsV1.mjs +++ /dev/null @@ -1,13 +0,0 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" -import { DisplayNamesFallback_js_to_rust, DisplayNamesFallback_rust_to_js } from "./DisplayNamesFallback.mjs" -import { DisplayNamesStyle_js_to_rust, DisplayNamesStyle_rust_to_js } from "./DisplayNamesStyle.mjs" -import { LanguageDisplay_js_to_rust, LanguageDisplay_rust_to_js } from "./LanguageDisplay.mjs" - -export class DisplayNamesOptionsV1 { - constructor(underlying) { - this.style = DisplayNamesStyle_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, underlying)]; - this.fallback = DisplayNamesFallback_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, underlying + 4)]; - this.language_display = LanguageDisplay_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, underlying + 8)]; - } -} diff --git a/ffi/capi/bindings/js/DisplayNamesStyle.d.ts b/ffi/capi/bindings/js/DisplayNamesStyle.d.ts index c57a331da6d..43775a433f5 100644 --- a/ffi/capi/bindings/js/DisplayNamesStyle.d.ts +++ b/ffi/capi/bindings/js/DisplayNamesStyle.d.ts @@ -1,22 +1,27 @@ +// generated by diplomat-tool +import type { pointer, char } from "./diplomat-runtime.d.ts"; + +// Base enumerator definition +/** See the [Rust documentation for `Style`](https://docs.rs/icu/latest/icu/displaynames/options/enum.Style.html) for more information. +*/ +export class DisplayNamesStyle { + constructor(value : DisplayNamesStyle | string); + + get value() : string; + + get ffiValue() : number; + + static Auto : DisplayNamesStyle; + + static Narrow : DisplayNamesStyle; + + static Short : DisplayNamesStyle; + + static Long : DisplayNamesStyle; + + static Menu : DisplayNamesStyle; + + + -/** - - * See the {@link https://docs.rs/icu/latest/icu/displaynames/options/enum.Style.html Rust documentation for `Style`} for more information. - */ -export enum DisplayNamesStyle { - /** - */ - Auto = 'Auto', - /** - */ - Narrow = 'Narrow', - /** - */ - Short = 'Short', - /** - */ - Long = 'Long', - /** - */ - Menu = 'Menu', } \ No newline at end of file diff --git a/ffi/capi/bindings/js/DisplayNamesStyle.mjs b/ffi/capi/bindings/js/DisplayNamesStyle.mjs index 052d1aeed4d..494d14c08df 100644 --- a/ffi/capi/bindings/js/DisplayNamesStyle.mjs +++ b/ffi/capi/bindings/js/DisplayNamesStyle.mjs @@ -1,26 +1,53 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" - -export const DisplayNamesStyle_js_to_rust = { - "Auto": 0, - "Narrow": 1, - "Short": 2, - "Long": 3, - "Menu": 4, -}; - -export const DisplayNamesStyle_rust_to_js = { - [0]: "Auto", - [1]: "Narrow", - [2]: "Short", - [3]: "Long", - [4]: "Menu", -}; - -export const DisplayNamesStyle = { - "Auto": "Auto", - "Narrow": "Narrow", - "Short": "Short", - "Long": "Long", - "Menu": "Menu", -}; +// generated by diplomat-tool +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; + +// Base enumerator definition +/** See the [Rust documentation for `Style`](https://docs.rs/icu/latest/icu/displaynames/options/enum.Style.html) for more information. +*/ +export class DisplayNamesStyle { + #value = undefined; + + static values = new Map([ + ["Auto", 0], + ["Narrow", 1], + ["Short", 2], + ["Long", 3], + ["Menu", 4] + ]); + constructor(value) { + if (value instanceof DisplayNamesStyle) { + this.#value = value.value; + return; + } + + if (DisplayNamesStyle.values.has(value)) { + this.#value = value; + return; + } + + throw TypeError(value + " is not a DisplayNamesStyle and does not correspond to any of its enumerator values."); + } + + get value() { + return this.#value; + } + + get ffiValue() { + return DisplayNamesStyle.values.get(this.#value); + } + + static Auto = new DisplayNamesStyle("Auto"); + + static Narrow = new DisplayNamesStyle("Narrow"); + + static Short = new DisplayNamesStyle("Short"); + + static Long = new DisplayNamesStyle("Long"); + + static Menu = new DisplayNamesStyle("Menu"); + + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/Error.d.ts b/ffi/capi/bindings/js/Error.d.ts index 0f63f71225f..babcaeb0287 100644 --- a/ffi/capi/bindings/js/Error.d.ts +++ b/ffi/capi/bindings/js/Error.d.ts @@ -1,71 +1,59 @@ +// generated by diplomat-tool +import type { pointer, char } from "./diplomat-runtime.d.ts"; + +// Base enumerator definition +/** Legacy error +* +*Additional information: [1](https://docs.rs/icu/latest/icu/datetime/enum.DateTimeError.html), [2](https://docs.rs/icu/latest/icu/provider/struct.DataError.html), [3](https://docs.rs/icu/latest/icu/provider/enum.DataErrorKind.html) +*/ +export class Error { + constructor(value : Error | string); + + get value() : string; + + get ffiValue() : number; + + static UnknownError : Error; + + static DataMissingDataMarkerError : Error; + + static DataMissingLocaleError : Error; + + static DataNeedsLocaleError : Error; + + static DataExtraneousLocaleError : Error; + + static DataFilteredResourceError : Error; + + static DataMismatchedTypeError : Error; + + static DataCustomError : Error; + + static DataIoError : Error; + + static DataUnavailableBufferFormatError : Error; + + static PropertyUnexpectedPropertyNameError : Error; + + static DateTimePatternError : Error; + + static DateTimeMissingInputFieldError : Error; + + static DateTimeSkeletonError : Error; + + static DateTimeUnsupportedFieldError : Error; + + static DateTimeUnsupportedOptionsError : Error; + + static DateTimeMissingWeekdaySymbolError : Error; + + static DateTimeMissingMonthSymbolError : Error; + + static DateTimeFixedDecimalError : Error; + + static DateTimeMismatchedCalendarError : Error; + + + -/** - - * Legacy error - - * Additional information: {@link https://docs.rs/icu/latest/icu/datetime/enum.DateTimeError.html 1}, {@link https://docs.rs/icu/latest/icu/provider/struct.DataError.html 2}, {@link https://docs.rs/icu/latest/icu/provider/enum.DataErrorKind.html 3} - */ -export enum Error { - /** - - * The error is not currently categorized as Error. Please file a bug - */ - UnknownError = 'UnknownError', - /** - */ - DataMissingDataMarkerError = 'DataMissingDataMarkerError', - /** - */ - DataMissingLocaleError = 'DataMissingLocaleError', - /** - */ - DataNeedsLocaleError = 'DataNeedsLocaleError', - /** - */ - DataExtraneousLocaleError = 'DataExtraneousLocaleError', - /** - */ - DataFilteredResourceError = 'DataFilteredResourceError', - /** - */ - DataMismatchedTypeError = 'DataMismatchedTypeError', - /** - */ - DataCustomError = 'DataCustomError', - /** - */ - DataIoError = 'DataIoError', - /** - */ - DataUnavailableBufferFormatError = 'DataUnavailableBufferFormatError', - /** - */ - PropertyUnexpectedPropertyNameError = 'PropertyUnexpectedPropertyNameError', - /** - */ - DateTimePatternError = 'DateTimePatternError', - /** - */ - DateTimeMissingInputFieldError = 'DateTimeMissingInputFieldError', - /** - */ - DateTimeSkeletonError = 'DateTimeSkeletonError', - /** - */ - DateTimeUnsupportedFieldError = 'DateTimeUnsupportedFieldError', - /** - */ - DateTimeUnsupportedOptionsError = 'DateTimeUnsupportedOptionsError', - /** - */ - DateTimeMissingWeekdaySymbolError = 'DateTimeMissingWeekdaySymbolError', - /** - */ - DateTimeMissingMonthSymbolError = 'DateTimeMissingMonthSymbolError', - /** - */ - DateTimeFixedDecimalError = 'DateTimeFixedDecimalError', - /** - */ - DateTimeMismatchedCalendarError = 'DateTimeMismatchedCalendarError', } \ No newline at end of file diff --git a/ffi/capi/bindings/js/Error.mjs b/ffi/capi/bindings/js/Error.mjs index dfa2bd68ce2..090e5299043 100644 --- a/ffi/capi/bindings/js/Error.mjs +++ b/ffi/capi/bindings/js/Error.mjs @@ -1,71 +1,100 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" - -export const Error_js_to_rust = { - "UnknownError": 0, - "DataMissingDataMarkerError": 256, - "DataMissingLocaleError": 258, - "DataNeedsLocaleError": 260, - "DataExtraneousLocaleError": 261, - "DataFilteredResourceError": 262, - "DataMismatchedTypeError": 263, - "DataCustomError": 266, - "DataIoError": 267, - "DataUnavailableBufferFormatError": 268, - "PropertyUnexpectedPropertyNameError": 1026, - "DateTimePatternError": 2048, - "DateTimeMissingInputFieldError": 2049, - "DateTimeSkeletonError": 2050, - "DateTimeUnsupportedFieldError": 2051, - "DateTimeUnsupportedOptionsError": 2052, - "DateTimeMissingWeekdaySymbolError": 2053, - "DateTimeMissingMonthSymbolError": 2054, - "DateTimeFixedDecimalError": 2055, - "DateTimeMismatchedCalendarError": 2056, -}; - -export const Error_rust_to_js = { - [0]: "UnknownError", - [256]: "DataMissingDataMarkerError", - [258]: "DataMissingLocaleError", - [260]: "DataNeedsLocaleError", - [261]: "DataExtraneousLocaleError", - [262]: "DataFilteredResourceError", - [263]: "DataMismatchedTypeError", - [266]: "DataCustomError", - [267]: "DataIoError", - [268]: "DataUnavailableBufferFormatError", - [1026]: "PropertyUnexpectedPropertyNameError", - [2048]: "DateTimePatternError", - [2049]: "DateTimeMissingInputFieldError", - [2050]: "DateTimeSkeletonError", - [2051]: "DateTimeUnsupportedFieldError", - [2052]: "DateTimeUnsupportedOptionsError", - [2053]: "DateTimeMissingWeekdaySymbolError", - [2054]: "DateTimeMissingMonthSymbolError", - [2055]: "DateTimeFixedDecimalError", - [2056]: "DateTimeMismatchedCalendarError", -}; - -export const Error = { - "UnknownError": "UnknownError", - "DataMissingDataMarkerError": "DataMissingDataMarkerError", - "DataMissingLocaleError": "DataMissingLocaleError", - "DataNeedsLocaleError": "DataNeedsLocaleError", - "DataExtraneousLocaleError": "DataExtraneousLocaleError", - "DataFilteredResourceError": "DataFilteredResourceError", - "DataMismatchedTypeError": "DataMismatchedTypeError", - "DataCustomError": "DataCustomError", - "DataIoError": "DataIoError", - "DataUnavailableBufferFormatError": "DataUnavailableBufferFormatError", - "PropertyUnexpectedPropertyNameError": "PropertyUnexpectedPropertyNameError", - "DateTimePatternError": "DateTimePatternError", - "DateTimeMissingInputFieldError": "DateTimeMissingInputFieldError", - "DateTimeSkeletonError": "DateTimeSkeletonError", - "DateTimeUnsupportedFieldError": "DateTimeUnsupportedFieldError", - "DateTimeUnsupportedOptionsError": "DateTimeUnsupportedOptionsError", - "DateTimeMissingWeekdaySymbolError": "DateTimeMissingWeekdaySymbolError", - "DateTimeMissingMonthSymbolError": "DateTimeMissingMonthSymbolError", - "DateTimeFixedDecimalError": "DateTimeFixedDecimalError", - "DateTimeMismatchedCalendarError": "DateTimeMismatchedCalendarError", -}; +// generated by diplomat-tool +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; + +// Base enumerator definition +/** Legacy error +* +*Additional information: [1](https://docs.rs/icu/latest/icu/datetime/enum.DateTimeError.html), [2](https://docs.rs/icu/latest/icu/provider/struct.DataError.html), [3](https://docs.rs/icu/latest/icu/provider/enum.DataErrorKind.html) +*/ +export class Error { + #value = undefined; + + static values = new Map([ + ["UnknownError", 0], + ["DataMissingDataMarkerError", 256], + ["DataMissingLocaleError", 258], + ["DataNeedsLocaleError", 260], + ["DataExtraneousLocaleError", 261], + ["DataFilteredResourceError", 262], + ["DataMismatchedTypeError", 263], + ["DataCustomError", 266], + ["DataIoError", 267], + ["DataUnavailableBufferFormatError", 268], + ["PropertyUnexpectedPropertyNameError", 1026], + ["DateTimePatternError", 2048], + ["DateTimeMissingInputFieldError", 2049], + ["DateTimeSkeletonError", 2050], + ["DateTimeUnsupportedFieldError", 2051], + ["DateTimeUnsupportedOptionsError", 2052], + ["DateTimeMissingWeekdaySymbolError", 2053], + ["DateTimeMissingMonthSymbolError", 2054], + ["DateTimeFixedDecimalError", 2055], + ["DateTimeMismatchedCalendarError", 2056] + ]); + constructor(value) { + if (value instanceof Error) { + this.#value = value.value; + return; + } + + if (Error.values.has(value)) { + this.#value = value; + return; + } + + throw TypeError(value + " is not a Error and does not correspond to any of its enumerator values."); + } + + get value() { + return this.#value; + } + + get ffiValue() { + return Error.values.get(this.#value); + } + + static UnknownError = new Error("UnknownError"); + + static DataMissingDataMarkerError = new Error("DataMissingDataMarkerError"); + + static DataMissingLocaleError = new Error("DataMissingLocaleError"); + + static DataNeedsLocaleError = new Error("DataNeedsLocaleError"); + + static DataExtraneousLocaleError = new Error("DataExtraneousLocaleError"); + + static DataFilteredResourceError = new Error("DataFilteredResourceError"); + + static DataMismatchedTypeError = new Error("DataMismatchedTypeError"); + + static DataCustomError = new Error("DataCustomError"); + + static DataIoError = new Error("DataIoError"); + + static DataUnavailableBufferFormatError = new Error("DataUnavailableBufferFormatError"); + + static PropertyUnexpectedPropertyNameError = new Error("PropertyUnexpectedPropertyNameError"); + + static DateTimePatternError = new Error("DateTimePatternError"); + + static DateTimeMissingInputFieldError = new Error("DateTimeMissingInputFieldError"); + + static DateTimeSkeletonError = new Error("DateTimeSkeletonError"); + + static DateTimeUnsupportedFieldError = new Error("DateTimeUnsupportedFieldError"); + + static DateTimeUnsupportedOptionsError = new Error("DateTimeUnsupportedOptionsError"); + + static DateTimeMissingWeekdaySymbolError = new Error("DateTimeMissingWeekdaySymbolError"); + + static DateTimeMissingMonthSymbolError = new Error("DateTimeMissingMonthSymbolError"); + + static DateTimeFixedDecimalError = new Error("DateTimeFixedDecimalError"); + + static DateTimeMismatchedCalendarError = new Error("DateTimeMismatchedCalendarError"); + + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/FixedDecimal.d.ts b/ffi/capi/bindings/js/FixedDecimal.d.ts index ab764af37fd..c3f5ebbadce 100644 --- a/ffi/capi/bindings/js/FixedDecimal.d.ts +++ b/ffi/capi/bindings/js/FixedDecimal.d.ts @@ -1,267 +1,79 @@ -import { u8, i16, i32, u32, i64, u64, f64 } from "./diplomat-runtime" -import { FFIError } from "./diplomat-runtime" -import { FixedDecimalLimitError } from "./FixedDecimalLimitError"; -import { FixedDecimalParseError } from "./FixedDecimalParseError"; -import { FixedDecimalRoundingIncrement } from "./FixedDecimalRoundingIncrement"; -import { FixedDecimalRoundingMode } from "./FixedDecimalRoundingMode"; -import { FixedDecimalSign } from "./FixedDecimalSign"; -import { FixedDecimalSignDisplay } from "./FixedDecimalSignDisplay"; - -/** - - * See the {@link https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html Rust documentation for `FixedDecimal`} for more information. - */ -export class FixedDecimal { - - /** - - * Construct an {@link FixedDecimal `FixedDecimal`} from an integer. - - * See the {@link https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html Rust documentation for `FixedDecimal`} for more information. - */ - static create_from_i32(v: i32): FixedDecimal; - - /** - - * Construct an {@link FixedDecimal `FixedDecimal`} from an integer. - - * See the {@link https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html Rust documentation for `FixedDecimal`} for more information. - */ - static create_from_u32(v: u32): FixedDecimal; - - /** - - * Construct an {@link FixedDecimal `FixedDecimal`} from an integer. - - * See the {@link https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html Rust documentation for `FixedDecimal`} for more information. - */ - static create_from_i64(v: i64): FixedDecimal; - - /** - - * Construct an {@link FixedDecimal `FixedDecimal`} from an integer. - - * See the {@link https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html Rust documentation for `FixedDecimal`} for more information. - */ - static create_from_u64(v: u64): FixedDecimal; - - /** - - * Construct an {@link FixedDecimal `FixedDecimal`} from an integer-valued float - - * See the {@link https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.try_from_f64 Rust documentation for `try_from_f64`} for more information. - - * See the {@link https://docs.rs/fixed_decimal/latest/fixed_decimal/enum.FloatPrecision.html Rust documentation for `FloatPrecision`} for more information. - * @throws {@link FFIError}<{@link FixedDecimalLimitError}> - */ - static create_from_f64_with_integer_precision(f: f64): FixedDecimal | never; - - /** - - * Construct an {@link FixedDecimal `FixedDecimal`} from an float, with a given power of 10 for the lower magnitude - - * See the {@link https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.try_from_f64 Rust documentation for `try_from_f64`} for more information. - - * See the {@link https://docs.rs/fixed_decimal/latest/fixed_decimal/enum.FloatPrecision.html Rust documentation for `FloatPrecision`} for more information. - * @throws {@link FFIError}<{@link FixedDecimalLimitError}> - */ - static create_from_f64_with_lower_magnitude(f: f64, magnitude: i16): FixedDecimal | never; - - /** - - * Construct an {@link FixedDecimal `FixedDecimal`} from an float, for a given number of significant digits - - * See the {@link https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.try_from_f64 Rust documentation for `try_from_f64`} for more information. - - * See the {@link https://docs.rs/fixed_decimal/latest/fixed_decimal/enum.FloatPrecision.html Rust documentation for `FloatPrecision`} for more information. - * @throws {@link FFIError}<{@link FixedDecimalLimitError}> - */ - static create_from_f64_with_significant_digits(f: f64, digits: u8): FixedDecimal | never; - - /** - - * Construct an {@link FixedDecimal `FixedDecimal`} from an float, with enough digits to recover the original floating point in IEEE 754 without needing trailing zeros - - * See the {@link https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.try_from_f64 Rust documentation for `try_from_f64`} for more information. +// generated by diplomat-tool +import type { FixedDecimalRoundingIncrement } from "./FixedDecimalRoundingIncrement" +import type { FixedDecimalRoundingMode } from "./FixedDecimalRoundingMode" +import type { FixedDecimalSign } from "./FixedDecimalSign" +import type { FixedDecimalSignDisplay } from "./FixedDecimalSignDisplay" +import type { pointer, char } from "./diplomat-runtime.d.ts"; - * See the {@link https://docs.rs/fixed_decimal/latest/fixed_decimal/enum.FloatPrecision.html Rust documentation for `FloatPrecision`} for more information. - * @throws {@link FFIError}<{@link FixedDecimalLimitError}> - */ - static create_from_f64_with_floating_precision(f: f64): FixedDecimal | never; - /** - - * Construct an {@link FixedDecimal `FixedDecimal`} from a string. - - * See the {@link https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.from_str Rust documentation for `from_str`} for more information. - * @throws {@link FFIError}<{@link FixedDecimalParseError}> - */ - static create_from_string(v: string): FixedDecimal | never; - - /** - - * See the {@link https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.digit_at Rust documentation for `digit_at`} for more information. - */ - digit_at(magnitude: i16): u8; - - /** - - * See the {@link https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.magnitude_range Rust documentation for `magnitude_range`} for more information. - */ - magnitude_start(): i16; - - /** - - * See the {@link https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.magnitude_range Rust documentation for `magnitude_range`} for more information. - */ - magnitude_end(): i16; - - /** - - * See the {@link https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.nonzero_magnitude_start Rust documentation for `nonzero_magnitude_start`} for more information. - */ - nonzero_magnitude_start(): i16; - - /** - - * See the {@link https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.nonzero_magnitude_end Rust documentation for `nonzero_magnitude_end`} for more information. - */ - nonzero_magnitude_end(): i16; - - /** - - * See the {@link https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.is_zero Rust documentation for `is_zero`} for more information. - */ - is_zero(): boolean; - - /** - - * Multiply the {@link FixedDecimal `FixedDecimal`} by a given power of ten. - - * See the {@link https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.multiply_pow10 Rust documentation for `multiply_pow10`} for more information. - */ - multiply_pow10(power: i16): void; - - /** - - * See the {@link https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.sign Rust documentation for `sign`} for more information. - */ - sign(): FixedDecimalSign; - - /** - - * Set the sign of the {@link FixedDecimal `FixedDecimal`}. - - * See the {@link https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.set_sign Rust documentation for `set_sign`} for more information. - */ - set_sign(sign: FixedDecimalSign): void; - - /** - - * See the {@link https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.apply_sign_display Rust documentation for `apply_sign_display`} for more information. - */ - apply_sign_display(sign_display: FixedDecimalSignDisplay): void; - - /** - - * See the {@link https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.trim_start Rust documentation for `trim_start`} for more information. - */ - trim_start(): void; - - /** +/** See the [Rust documentation for `FixedDecimal`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html) for more information. +*/ +export class FixedDecimal { + - * See the {@link https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.trim_end Rust documentation for `trim_end`} for more information. - */ - trim_end(): void; + get ffiValue(): pointer; - /** - * Zero-pad the {@link FixedDecimal `FixedDecimal`} on the left to a particular position + static fromInteger(v: number): FixedDecimal; - * See the {@link https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.pad_start Rust documentation for `pad_start`} for more information. - */ - pad_start(position: i16): void; + static fromBigInt(v: bigint): FixedDecimal; - /** + static fromNumberWithLowerMagnitude(f: number, magnitude: number): FixedDecimal; - * Zero-pad the {@link FixedDecimal `FixedDecimal`} on the right to a particular position + static fromNumberWithSignificantDigits(f: number, digits: number): FixedDecimal; - * See the {@link https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.pad_end Rust documentation for `pad_end`} for more information. - */ - pad_end(position: i16): void; + static fromNumberWithFloatingPrecision(f: number): FixedDecimal; - /** + static fromString(v: string): FixedDecimal; - * Truncate the {@link FixedDecimal `FixedDecimal`} on the left to a particular position, deleting digits if necessary. This is useful for, e.g. abbreviating years ("2022" -> "22") + digitAt(magnitude: number): number; - * See the {@link https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.set_max_position Rust documentation for `set_max_position`} for more information. - */ - set_max_position(position: i16): void; + get magnitudeStart(): number; - /** + get magnitudeEnd(): number; - * Round the number at a particular digit position. + get nonzeroMagnitudeStart(): number; - * This uses half to even rounding, which resolves ties by selecting the nearest even integer to the original value. + get nonzeroMagnitudeEnd(): number; - * See the {@link https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.round Rust documentation for `round`} for more information. - */ - round(position: i16): void; + get isZero(): boolean; - /** + multiplyPow10(power: number): void; - * See the {@link https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.ceil Rust documentation for `ceil`} for more information. - */ - ceil(position: i16): void; + get sign(): FixedDecimalSign; - /** + set sign(sign: FixedDecimalSign); - * See the {@link https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.expand Rust documentation for `expand`} for more information. - */ - expand(position: i16): void; + applySignDisplay(signDisplay: FixedDecimalSignDisplay): void; - /** + trimStart(): void; - * See the {@link https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.floor Rust documentation for `floor`} for more information. - */ - floor(position: i16): void; + trimEnd(): void; - /** + padStart(position: number): void; - * See the {@link https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.trunc Rust documentation for `trunc`} for more information. - */ - trunc(position: i16): void; + padEnd(position: number): void; - /** + setMaxPosition(position: number): void; - * See the {@link https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.round_with_mode Rust documentation for `round_with_mode`} for more information. - */ - round_with_mode(position: i16, mode: FixedDecimalRoundingMode): void; + round(position: number): void; - /** + ceil(position: number): void; - * See the {@link https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.round_with_mode_and_increment Rust documentation for `round_with_mode_and_increment`} for more information. - */ - round_with_mode_and_increment(position: i16, mode: FixedDecimalRoundingMode, increment: FixedDecimalRoundingIncrement): void; + expand(position: number): void; - /** + floor(position: number): void; - * Concatenates `other` to the end of `self`. + trunc(position: number): void; - * If successful, `other` will be set to 0 and a successful status is returned. + roundWithMode(position: number, mode: FixedDecimalRoundingMode): void; - * If not successful, `other` will be unchanged and an error is returned. + roundWithModeAndIncrement(position: number, mode: FixedDecimalRoundingMode, increment: FixedDecimalRoundingIncrement): void; - * See the {@link https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.concatenate_end Rust documentation for `concatenate_end`} for more information. - * @throws {@link FFIError} - */ - concatenate_end(other: FixedDecimal): void | never; + concatenateEnd(other: FixedDecimal): boolean; - /** + toString(): string; - * Format the {@link FixedDecimal `FixedDecimal`} as a string. + - * See the {@link https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.write_to Rust documentation for `write_to`} for more information. - */ - to_string(): string; -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/FixedDecimal.mjs b/ffi/capi/bindings/js/FixedDecimal.mjs index 7c5a8e78450..cf6c876a990 100644 --- a/ffi/capi/bindings/js/FixedDecimal.mjs +++ b/ffi/capi/bindings/js/FixedDecimal.mjs @@ -1,230 +1,397 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" -import { FixedDecimalLimitError_js_to_rust, FixedDecimalLimitError_rust_to_js } from "./FixedDecimalLimitError.mjs" -import { FixedDecimalParseError_js_to_rust, FixedDecimalParseError_rust_to_js } from "./FixedDecimalParseError.mjs" -import { FixedDecimalRoundingIncrement_js_to_rust, FixedDecimalRoundingIncrement_rust_to_js } from "./FixedDecimalRoundingIncrement.mjs" -import { FixedDecimalRoundingMode_js_to_rust, FixedDecimalRoundingMode_rust_to_js } from "./FixedDecimalRoundingMode.mjs" -import { FixedDecimalSign_js_to_rust, FixedDecimalSign_rust_to_js } from "./FixedDecimalSign.mjs" -import { FixedDecimalSignDisplay_js_to_rust, FixedDecimalSignDisplay_rust_to_js } from "./FixedDecimalSignDisplay.mjs" - -const FixedDecimal_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XFixedDecimal_destroy(underlying); +// generated by diplomat-tool +import { FixedDecimalLimitError } from "./FixedDecimalLimitError.mjs" +import { FixedDecimalParseError } from "./FixedDecimalParseError.mjs" +import { FixedDecimalRoundingIncrement } from "./FixedDecimalRoundingIncrement.mjs" +import { FixedDecimalRoundingMode } from "./FixedDecimalRoundingMode.mjs" +import { FixedDecimalSign } from "./FixedDecimalSign.mjs" +import { FixedDecimalSignDisplay } from "./FixedDecimalSignDisplay.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; + + +/** See the [Rust documentation for `FixedDecimal`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html) for more information. +*/ + +const FixedDecimal_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XFixedDecimal_destroy(ptr); }); - export class FixedDecimal { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - FixedDecimal_box_destroy_registry.register(this, underlying); - } - } - - static create_from_i32(arg_v) { - return new FixedDecimal(wasm.ICU4XFixedDecimal_create_from_i32(arg_v), true, []); - } - - static create_from_u32(arg_v) { - return new FixedDecimal(wasm.ICU4XFixedDecimal_create_from_u32(arg_v), true, []); - } - - static create_from_i64(arg_v) { - return new FixedDecimal(wasm.ICU4XFixedDecimal_create_from_i64(arg_v), true, []); - } - - static create_from_u64(arg_v) { - return new FixedDecimal(wasm.ICU4XFixedDecimal_create_from_u64(arg_v), true, []); - } - - static create_from_f64_with_integer_precision(arg_f) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XFixedDecimal_create_from_f64_with_integer_precision(diplomat_receive_buffer, arg_f); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new FixedDecimal(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = FixedDecimalLimitError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static create_from_f64_with_lower_magnitude(arg_f, arg_magnitude) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XFixedDecimal_create_from_f64_with_lower_magnitude(diplomat_receive_buffer, arg_f, arg_magnitude); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new FixedDecimal(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = FixedDecimalLimitError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static create_from_f64_with_significant_digits(arg_f, arg_digits) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XFixedDecimal_create_from_f64_with_significant_digits(diplomat_receive_buffer, arg_f, arg_digits); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new FixedDecimal(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = FixedDecimalLimitError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static create_from_f64_with_floating_precision(arg_f) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XFixedDecimal_create_from_f64_with_floating_precision(diplomat_receive_buffer, arg_f); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new FixedDecimal(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = FixedDecimalLimitError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static create_from_string(arg_v) { - const buf_arg_v = diplomatRuntime.DiplomatBuf.str8(wasm, arg_v); - const diplomat_out = (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XFixedDecimal_create_from_string(diplomat_receive_buffer, buf_arg_v.ptr, buf_arg_v.size); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new FixedDecimal(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = FixedDecimalParseError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - buf_arg_v.free(); - return diplomat_out; - } - - digit_at(arg_magnitude) { - return wasm.ICU4XFixedDecimal_digit_at(this.underlying, arg_magnitude); - } - - magnitude_start() { - return wasm.ICU4XFixedDecimal_magnitude_start(this.underlying); - } - - magnitude_end() { - return wasm.ICU4XFixedDecimal_magnitude_end(this.underlying); - } - - nonzero_magnitude_start() { - return wasm.ICU4XFixedDecimal_nonzero_magnitude_start(this.underlying); - } - - nonzero_magnitude_end() { - return wasm.ICU4XFixedDecimal_nonzero_magnitude_end(this.underlying); - } - - is_zero() { - return wasm.ICU4XFixedDecimal_is_zero(this.underlying); - } - - multiply_pow10(arg_power) { - wasm.ICU4XFixedDecimal_multiply_pow10(this.underlying, arg_power); - } - - sign() { - return FixedDecimalSign_rust_to_js[wasm.ICU4XFixedDecimal_sign(this.underlying)]; - } - - set_sign(arg_sign) { - wasm.ICU4XFixedDecimal_set_sign(this.underlying, FixedDecimalSign_js_to_rust[arg_sign]); - } - - apply_sign_display(arg_sign_display) { - wasm.ICU4XFixedDecimal_apply_sign_display(this.underlying, FixedDecimalSignDisplay_js_to_rust[arg_sign_display]); - } - - trim_start() { - wasm.ICU4XFixedDecimal_trim_start(this.underlying); - } - - trim_end() { - wasm.ICU4XFixedDecimal_trim_end(this.underlying); - } - - pad_start(arg_position) { - wasm.ICU4XFixedDecimal_pad_start(this.underlying, arg_position); - } - - pad_end(arg_position) { - wasm.ICU4XFixedDecimal_pad_end(this.underlying, arg_position); - } - - set_max_position(arg_position) { - wasm.ICU4XFixedDecimal_set_max_position(this.underlying, arg_position); - } - - round(arg_position) { - wasm.ICU4XFixedDecimal_round(this.underlying, arg_position); - } - - ceil(arg_position) { - wasm.ICU4XFixedDecimal_ceil(this.underlying, arg_position); - } - - expand(arg_position) { - wasm.ICU4XFixedDecimal_expand(this.underlying, arg_position); - } - - floor(arg_position) { - wasm.ICU4XFixedDecimal_floor(this.underlying, arg_position); - } - - trunc(arg_position) { - wasm.ICU4XFixedDecimal_trunc(this.underlying, arg_position); - } - - round_with_mode(arg_position, arg_mode) { - wasm.ICU4XFixedDecimal_round_with_mode(this.underlying, arg_position, FixedDecimalRoundingMode_js_to_rust[arg_mode]); - } - - round_with_mode_and_increment(arg_position, arg_mode, arg_increment) { - wasm.ICU4XFixedDecimal_round_with_mode_and_increment(this.underlying, arg_position, FixedDecimalRoundingMode_js_to_rust[arg_mode], FixedDecimalRoundingIncrement_js_to_rust[arg_increment]); - } - - concatenate_end(arg_other) { - return (() => { - const is_ok = wasm.ICU4XFixedDecimal_concatenate_end(this.underlying, arg_other.underlying) == 1; - if (!is_ok) { - throw new diplomatRuntime.FFIError(undefined); - } - })(); - } - - to_string() { - return diplomatRuntime.withDiplomatWrite(wasm, (write) => { - return wasm.ICU4XFixedDecimal_to_string(this.underlying, write); - }); - } -} + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + + constructor(ptr, selfEdge) { + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + FixedDecimal_box_destroy_registry.register(this, this.#ptr); + } + + get ffiValue() { + return this.#ptr; + } + + + static fromInteger(v) { + const result = wasm.ICU4XFixedDecimal_create_from_i32(v); + + try { + + return new FixedDecimal(result, []); + } finally { + + } + } + + static fromBigInt(v) { + const result = wasm.ICU4XFixedDecimal_create_from_i64(v); + + try { + + return new FixedDecimal(result, []); + } finally { + + } + } + + static fromNumberWithLowerMagnitude(f, magnitude) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XFixedDecimal_create_from_f64_with_lower_magnitude(diplomat_receive_buffer, f, magnitude); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = FixedDecimalLimitError[Array.from(FixedDecimalLimitError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('FixedDecimalLimitError: ' + cause.value, { cause }); + } + return new FixedDecimal(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static fromNumberWithSignificantDigits(f, digits) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XFixedDecimal_create_from_f64_with_significant_digits(diplomat_receive_buffer, f, digits); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = FixedDecimalLimitError[Array.from(FixedDecimalLimitError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('FixedDecimalLimitError: ' + cause.value, { cause }); + } + return new FixedDecimal(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static fromNumberWithFloatingPrecision(f) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XFixedDecimal_create_from_f64_with_floating_precision(diplomat_receive_buffer, f); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = FixedDecimalLimitError[Array.from(FixedDecimalLimitError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('FixedDecimalLimitError: ' + cause.value, { cause }); + } + return new FixedDecimal(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static fromString(v) { + + const vSlice = diplomatRuntime.DiplomatBuf.str8(wasm, v); + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XFixedDecimal_create_from_string(diplomat_receive_buffer, vSlice.ptr, vSlice.size); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = FixedDecimalParseError[Array.from(FixedDecimalParseError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('FixedDecimalParseError: ' + cause.value, { cause }); + } + return new FixedDecimal(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + vSlice.free(); + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + digitAt(magnitude) { + const result = wasm.ICU4XFixedDecimal_digit_at(this.ffiValue, magnitude); + + try { + + return result; + } finally { + + } + } + + get magnitudeStart() { + const result = wasm.ICU4XFixedDecimal_magnitude_start(this.ffiValue); + + try { + + return result; + } finally { + + } + } + + get magnitudeEnd() { + const result = wasm.ICU4XFixedDecimal_magnitude_end(this.ffiValue); + + try { + + return result; + } finally { + + } + } + + get nonzeroMagnitudeStart() { + const result = wasm.ICU4XFixedDecimal_nonzero_magnitude_start(this.ffiValue); + + try { + + return result; + } finally { + + } + } + + get nonzeroMagnitudeEnd() { + const result = wasm.ICU4XFixedDecimal_nonzero_magnitude_end(this.ffiValue); + + try { + + return result; + } finally { + + } + } + + get isZero() { + const result = wasm.ICU4XFixedDecimal_is_zero(this.ffiValue); + + try { + + return result; + } finally { + + } + } + + multiplyPow10(power) { + wasm.ICU4XFixedDecimal_multiply_pow10(this.ffiValue, power); + + try { + + } finally { + + } + } + + get sign() { + const result = wasm.ICU4XFixedDecimal_sign(this.ffiValue); + + try { + + return FixedDecimalSign[Array.from(FixedDecimalSign.values.keys())[result]]; + } finally { + + } + } + + set sign(sign) { + wasm.ICU4XFixedDecimal_set_sign(this.ffiValue, sign.ffiValue); + + try { + + } finally { + + } + } + + applySignDisplay(signDisplay) { + wasm.ICU4XFixedDecimal_apply_sign_display(this.ffiValue, signDisplay.ffiValue); + + try { + + } finally { + + } + } + + trimStart() { + wasm.ICU4XFixedDecimal_trim_start(this.ffiValue); + + try { + + } finally { + + } + } + + trimEnd() { + wasm.ICU4XFixedDecimal_trim_end(this.ffiValue); + + try { + + } finally { + + } + } + + padStart(position) { + wasm.ICU4XFixedDecimal_pad_start(this.ffiValue, position); + + try { + + } finally { + + } + } + + padEnd(position) { + wasm.ICU4XFixedDecimal_pad_end(this.ffiValue, position); + + try { + + } finally { + + } + } + + setMaxPosition(position) { + wasm.ICU4XFixedDecimal_set_max_position(this.ffiValue, position); + + try { + + } finally { + + } + } + + round(position) { + wasm.ICU4XFixedDecimal_round(this.ffiValue, position); + + try { + + } finally { + + } + } + + ceil(position) { + wasm.ICU4XFixedDecimal_ceil(this.ffiValue, position); + + try { + + } finally { + + } + } + + expand(position) { + wasm.ICU4XFixedDecimal_expand(this.ffiValue, position); + + try { + + } finally { + + } + } + + floor(position) { + wasm.ICU4XFixedDecimal_floor(this.ffiValue, position); + + try { + + } finally { + + } + } + + trunc(position) { + wasm.ICU4XFixedDecimal_trunc(this.ffiValue, position); + + try { + + } finally { + + } + } + + roundWithMode(position, mode) { + wasm.ICU4XFixedDecimal_round_with_mode(this.ffiValue, position, mode.ffiValue); + + try { + + } finally { + + } + } + + roundWithModeAndIncrement(position, mode, increment) { + wasm.ICU4XFixedDecimal_round_with_mode_and_increment(this.ffiValue, position, mode.ffiValue, increment.ffiValue); + + try { + + } finally { + + } + } + + concatenateEnd(other) { + const result = wasm.ICU4XFixedDecimal_concatenate_end(this.ffiValue, other.ffiValue); + + try { + + return result == 1; + } finally { + + } + } + + toString() { + + const write = wasm.diplomat_buffer_write_create(0); + wasm.ICU4XFixedDecimal_to_string(this.ffiValue, write); + + try { + + return diplomatRuntime.readString8(wasm, wasm.diplomat_buffer_write_get_bytes(write), wasm.diplomat_buffer_write_len(write)); + } finally { + + wasm.diplomat_buffer_write_destroy(write); + + } + } + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/FixedDecimalFormatter.d.ts b/ffi/capi/bindings/js/FixedDecimalFormatter.d.ts index d2397f25069..67f81cdd496 100644 --- a/ffi/capi/bindings/js/FixedDecimalFormatter.d.ts +++ b/ffi/capi/bindings/js/FixedDecimalFormatter.d.ts @@ -1,42 +1,25 @@ -import { FFIError } from "./diplomat-runtime" -import { DataError } from "./DataError"; -import { DataProvider } from "./DataProvider"; -import { DataStruct } from "./DataStruct"; -import { FixedDecimal } from "./FixedDecimal"; -import { FixedDecimalGroupingStrategy } from "./FixedDecimalGroupingStrategy"; -import { Locale } from "./Locale"; - -/** - - * An ICU4X Fixed Decimal Format object, capable of formatting a {@link FixedDecimal `FixedDecimal`} as a string. - - * See the {@link https://docs.rs/icu/latest/icu/decimal/struct.FixedDecimalFormatter.html Rust documentation for `FixedDecimalFormatter`} for more information. - */ +// generated by diplomat-tool +import type { DataProvider } from "./DataProvider" +import type { FixedDecimal } from "./FixedDecimal" +import type { FixedDecimalGroupingStrategy } from "./FixedDecimalGroupingStrategy" +import type { Locale } from "./Locale" +import type { pointer, char } from "./diplomat-runtime.d.ts"; + + +/** An ICU4X Fixed Decimal Format object, capable of formatting a [`FixedDecimal`] as a string. +* +*See the [Rust documentation for `FixedDecimalFormatter`](https://docs.rs/icu/latest/icu/decimal/struct.FixedDecimalFormatter.html) for more information. +*/ export class FixedDecimalFormatter { + - /** - - * Creates a new {@link FixedDecimalFormatter `FixedDecimalFormatter`} from locale data. - - * See the {@link https://docs.rs/icu/latest/icu/decimal/struct.FixedDecimalFormatter.html#method.try_new Rust documentation for `try_new`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static create_with_grouping_strategy(provider: DataProvider, locale: Locale, grouping_strategy: FixedDecimalGroupingStrategy): FixedDecimalFormatter | never; - - /** + get ffiValue(): pointer; - * Creates a new {@link FixedDecimalFormatter `FixedDecimalFormatter`} from preconstructed locale data in the form of an {@link DataStruct `DataStruct`} constructed from `DataStruct::create_decimal_symbols()`. - * The contents of the data struct will be consumed: if you wish to use the struct again it will have to be reconstructed. Passing a consumed struct to this method will return an error. - * @throws {@link FFIError}<{@link DataError}> - */ - static create_with_decimal_symbols_v1(data_struct: DataStruct, grouping_strategy: FixedDecimalGroupingStrategy): FixedDecimalFormatter | never; + static createWithGroupingStrategy(provider: DataProvider, locale: Locale, groupingStrategy: FixedDecimalGroupingStrategy): FixedDecimalFormatter; - /** + format(value: FixedDecimal): string; - * Formats a {@link FixedDecimal `FixedDecimal`} to a string. + - * See the {@link https://docs.rs/icu/latest/icu/decimal/struct.FixedDecimalFormatter.html#method.format Rust documentation for `format`} for more information. - */ - format(value: FixedDecimal): string; -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/FixedDecimalFormatter.mjs b/ffi/capi/bindings/js/FixedDecimalFormatter.mjs index 65d64fe03aa..204add3303d 100644 --- a/ffi/capi/bindings/js/FixedDecimalFormatter.mjs +++ b/ffi/capi/bindings/js/FixedDecimalFormatter.mjs @@ -1,59 +1,77 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" -import { DataError_js_to_rust, DataError_rust_to_js } from "./DataError.mjs" -import { FixedDecimalGroupingStrategy_js_to_rust, FixedDecimalGroupingStrategy_rust_to_js } from "./FixedDecimalGroupingStrategy.mjs" +// generated by diplomat-tool +import { DataError } from "./DataError.mjs" +import { DataProvider } from "./DataProvider.mjs" +import { FixedDecimal } from "./FixedDecimal.mjs" +import { FixedDecimalGroupingStrategy } from "./FixedDecimalGroupingStrategy.mjs" +import { Locale } from "./Locale.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -const FixedDecimalFormatter_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XFixedDecimalFormatter_destroy(underlying); -}); +/** An ICU4X Fixed Decimal Format object, capable of formatting a [`FixedDecimal`] as a string. +* +*See the [Rust documentation for `FixedDecimalFormatter`](https://docs.rs/icu/latest/icu/decimal/struct.FixedDecimalFormatter.html) for more information. +*/ + +const FixedDecimalFormatter_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XFixedDecimalFormatter_destroy(ptr); +}); export class FixedDecimalFormatter { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - FixedDecimalFormatter_box_destroy_registry.register(this, underlying); + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + + constructor(ptr, selfEdge) { + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + FixedDecimalFormatter_box_destroy_registry.register(this, this.#ptr); } - } - - static create_with_grouping_strategy(arg_provider, arg_locale, arg_grouping_strategy) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XFixedDecimalFormatter_create_with_grouping_strategy(diplomat_receive_buffer, arg_provider.underlying, arg_locale.underlying, FixedDecimalGroupingStrategy_js_to_rust[arg_grouping_strategy]); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new FixedDecimalFormatter(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static create_with_decimal_symbols_v1(arg_data_struct, arg_grouping_strategy) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XFixedDecimalFormatter_create_with_decimal_symbols_v1(diplomat_receive_buffer, arg_data_struct.underlying, FixedDecimalGroupingStrategy_js_to_rust[arg_grouping_strategy]); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new FixedDecimalFormatter(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - format(arg_value) { - return diplomatRuntime.withDiplomatWrite(wasm, (write) => { - return wasm.ICU4XFixedDecimalFormatter_format(this.underlying, arg_value.underlying, write); - }); - } -} + + get ffiValue() { + return this.#ptr; + } + + + static createWithGroupingStrategy(provider, locale, groupingStrategy) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XFixedDecimalFormatter_create_with_grouping_strategy(diplomat_receive_buffer, provider.ffiValue, locale.ffiValue, groupingStrategy.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new FixedDecimalFormatter(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + format(value) { + + const write = wasm.diplomat_buffer_write_create(0); + wasm.ICU4XFixedDecimalFormatter_format(this.ffiValue, value.ffiValue, write); + + try { + + return diplomatRuntime.readString8(wasm, wasm.diplomat_buffer_write_get_bytes(write), wasm.diplomat_buffer_write_len(write)); + } finally { + + wasm.diplomat_buffer_write_destroy(write); + + } + } + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/FixedDecimalGroupingStrategy.d.ts b/ffi/capi/bindings/js/FixedDecimalGroupingStrategy.d.ts index 7a4a8ceda60..582b2e3dbf1 100644 --- a/ffi/capi/bindings/js/FixedDecimalGroupingStrategy.d.ts +++ b/ffi/capi/bindings/js/FixedDecimalGroupingStrategy.d.ts @@ -1,19 +1,25 @@ +// generated by diplomat-tool +import type { pointer, char } from "./diplomat-runtime.d.ts"; + +// Base enumerator definition +/** See the [Rust documentation for `GroupingStrategy`](https://docs.rs/icu/latest/icu/decimal/options/enum.GroupingStrategy.html) for more information. +*/ +export class FixedDecimalGroupingStrategy { + constructor(value : FixedDecimalGroupingStrategy | string); + + get value() : string; + + get ffiValue() : number; + + static Auto : FixedDecimalGroupingStrategy; + + static Never : FixedDecimalGroupingStrategy; + + static Always : FixedDecimalGroupingStrategy; + + static Min2 : FixedDecimalGroupingStrategy; + + + -/** - - * See the {@link https://docs.rs/icu/latest/icu/decimal/options/enum.GroupingStrategy.html Rust documentation for `GroupingStrategy`} for more information. - */ -export enum FixedDecimalGroupingStrategy { - /** - */ - Auto = 'Auto', - /** - */ - Never = 'Never', - /** - */ - Always = 'Always', - /** - */ - Min2 = 'Min2', } \ No newline at end of file diff --git a/ffi/capi/bindings/js/FixedDecimalGroupingStrategy.mjs b/ffi/capi/bindings/js/FixedDecimalGroupingStrategy.mjs index ed76cef92ef..be9255ddf4f 100644 --- a/ffi/capi/bindings/js/FixedDecimalGroupingStrategy.mjs +++ b/ffi/capi/bindings/js/FixedDecimalGroupingStrategy.mjs @@ -1,23 +1,50 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" - -export const FixedDecimalGroupingStrategy_js_to_rust = { - "Auto": 0, - "Never": 1, - "Always": 2, - "Min2": 3, -}; - -export const FixedDecimalGroupingStrategy_rust_to_js = { - [0]: "Auto", - [1]: "Never", - [2]: "Always", - [3]: "Min2", -}; - -export const FixedDecimalGroupingStrategy = { - "Auto": "Auto", - "Never": "Never", - "Always": "Always", - "Min2": "Min2", -}; +// generated by diplomat-tool +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; + +// Base enumerator definition +/** See the [Rust documentation for `GroupingStrategy`](https://docs.rs/icu/latest/icu/decimal/options/enum.GroupingStrategy.html) for more information. +*/ +export class FixedDecimalGroupingStrategy { + #value = undefined; + + static values = new Map([ + ["Auto", 0], + ["Never", 1], + ["Always", 2], + ["Min2", 3] + ]); + constructor(value) { + if (value instanceof FixedDecimalGroupingStrategy) { + this.#value = value.value; + return; + } + + if (FixedDecimalGroupingStrategy.values.has(value)) { + this.#value = value; + return; + } + + throw TypeError(value + " is not a FixedDecimalGroupingStrategy and does not correspond to any of its enumerator values."); + } + + get value() { + return this.#value; + } + + get ffiValue() { + return FixedDecimalGroupingStrategy.values.get(this.#value); + } + + static Auto = new FixedDecimalGroupingStrategy("Auto"); + + static Never = new FixedDecimalGroupingStrategy("Never"); + + static Always = new FixedDecimalGroupingStrategy("Always"); + + static Min2 = new FixedDecimalGroupingStrategy("Min2"); + + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/FixedDecimalLimitError.d.ts b/ffi/capi/bindings/js/FixedDecimalLimitError.d.ts index eff2a1df360..1946012ba58 100644 --- a/ffi/capi/bindings/js/FixedDecimalLimitError.d.ts +++ b/ffi/capi/bindings/js/FixedDecimalLimitError.d.ts @@ -1,10 +1,19 @@ +// generated by diplomat-tool +import type { pointer, char } from "./diplomat-runtime.d.ts"; -/** +// Base enumerator definition +/** Additional information: [1](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.LimitError.html) +*/ +export class FixedDecimalLimitError { + constructor(value : FixedDecimalLimitError | string); + + get value() : string; + + get ffiValue() : number; + + static TodoZst : FixedDecimalLimitError; + + + - * Additional information: {@link https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.LimitError.html 1} - */ -export enum FixedDecimalLimitError { - /** - */ - TodoZst = 'TodoZst', } \ No newline at end of file diff --git a/ffi/capi/bindings/js/FixedDecimalLimitError.mjs b/ffi/capi/bindings/js/FixedDecimalLimitError.mjs index f51cf7a371a..021096e2839 100644 --- a/ffi/capi/bindings/js/FixedDecimalLimitError.mjs +++ b/ffi/capi/bindings/js/FixedDecimalLimitError.mjs @@ -1,14 +1,41 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" +// generated by diplomat-tool +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -export const FixedDecimalLimitError_js_to_rust = { - "TodoZst": 0, -}; +// Base enumerator definition +/** Additional information: [1](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.LimitError.html) +*/ +export class FixedDecimalLimitError { + #value = undefined; -export const FixedDecimalLimitError_rust_to_js = { - [0]: "TodoZst", -}; + static values = new Map([ + ["TodoZst", 0] + ]); + constructor(value) { + if (value instanceof FixedDecimalLimitError) { + this.#value = value.value; + return; + } -export const FixedDecimalLimitError = { - "TodoZst": "TodoZst", -}; + if (FixedDecimalLimitError.values.has(value)) { + this.#value = value; + return; + } + + throw TypeError(value + " is not a FixedDecimalLimitError and does not correspond to any of its enumerator values."); + } + + get value() { + return this.#value; + } + + get ffiValue() { + return FixedDecimalLimitError.values.get(this.#value); + } + + static TodoZst = new FixedDecimalLimitError("TodoZst"); + + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/FixedDecimalParseError.d.ts b/ffi/capi/bindings/js/FixedDecimalParseError.d.ts index f11ba322a15..66e77511c2d 100644 --- a/ffi/capi/bindings/js/FixedDecimalParseError.d.ts +++ b/ffi/capi/bindings/js/FixedDecimalParseError.d.ts @@ -1,16 +1,23 @@ +// generated by diplomat-tool +import type { pointer, char } from "./diplomat-runtime.d.ts"; + +// Base enumerator definition +/** Additional information: [1](https://docs.rs/fixed_decimal/latest/fixed_decimal/enum.ParseError.html) +*/ +export class FixedDecimalParseError { + constructor(value : FixedDecimalParseError | string); + + get value() : string; + + get ffiValue() : number; + + static Unknown : FixedDecimalParseError; + + static Limit : FixedDecimalParseError; + + static Syntax : FixedDecimalParseError; + + + -/** - - * Additional information: {@link https://docs.rs/fixed_decimal/latest/fixed_decimal/enum.ParseError.html 1} - */ -export enum FixedDecimalParseError { - /** - */ - Unknown = 'Unknown', - /** - */ - Limit = 'Limit', - /** - */ - Syntax = 'Syntax', } \ No newline at end of file diff --git a/ffi/capi/bindings/js/FixedDecimalParseError.mjs b/ffi/capi/bindings/js/FixedDecimalParseError.mjs index bc4c475ae6f..98e6c5f9412 100644 --- a/ffi/capi/bindings/js/FixedDecimalParseError.mjs +++ b/ffi/capi/bindings/js/FixedDecimalParseError.mjs @@ -1,20 +1,47 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" - -export const FixedDecimalParseError_js_to_rust = { - "Unknown": 0, - "Limit": 1, - "Syntax": 2, -}; - -export const FixedDecimalParseError_rust_to_js = { - [0]: "Unknown", - [1]: "Limit", - [2]: "Syntax", -}; - -export const FixedDecimalParseError = { - "Unknown": "Unknown", - "Limit": "Limit", - "Syntax": "Syntax", -}; +// generated by diplomat-tool +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; + +// Base enumerator definition +/** Additional information: [1](https://docs.rs/fixed_decimal/latest/fixed_decimal/enum.ParseError.html) +*/ +export class FixedDecimalParseError { + #value = undefined; + + static values = new Map([ + ["Unknown", 0], + ["Limit", 1], + ["Syntax", 2] + ]); + constructor(value) { + if (value instanceof FixedDecimalParseError) { + this.#value = value.value; + return; + } + + if (FixedDecimalParseError.values.has(value)) { + this.#value = value; + return; + } + + throw TypeError(value + " is not a FixedDecimalParseError and does not correspond to any of its enumerator values."); + } + + get value() { + return this.#value; + } + + get ffiValue() { + return FixedDecimalParseError.values.get(this.#value); + } + + static Unknown = new FixedDecimalParseError("Unknown"); + + static Limit = new FixedDecimalParseError("Limit"); + + static Syntax = new FixedDecimalParseError("Syntax"); + + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/FixedDecimalRoundingIncrement.d.ts b/ffi/capi/bindings/js/FixedDecimalRoundingIncrement.d.ts index 568e1baf131..88ff587d2ef 100644 --- a/ffi/capi/bindings/js/FixedDecimalRoundingIncrement.d.ts +++ b/ffi/capi/bindings/js/FixedDecimalRoundingIncrement.d.ts @@ -1,21 +1,27 @@ +// generated by diplomat-tool +import type { pointer, char } from "./diplomat-runtime.d.ts"; + +// Base enumerator definition +/** Increment used in a rounding operation. +* +*See the [Rust documentation for `RoundingIncrement`](https://docs.rs/fixed_decimal/latest/fixed_decimal/enum.RoundingIncrement.html) for more information. +*/ +export class FixedDecimalRoundingIncrement { + constructor(value : FixedDecimalRoundingIncrement | string); + + get value() : string; + + get ffiValue() : number; + + static MultiplesOf1 : FixedDecimalRoundingIncrement; + + static MultiplesOf2 : FixedDecimalRoundingIncrement; + + static MultiplesOf5 : FixedDecimalRoundingIncrement; + + static MultiplesOf25 : FixedDecimalRoundingIncrement; + + + -/** - - * Increment used in a rounding operation. - - * See the {@link https://docs.rs/fixed_decimal/latest/fixed_decimal/enum.RoundingIncrement.html Rust documentation for `RoundingIncrement`} for more information. - */ -export enum FixedDecimalRoundingIncrement { - /** - */ - MultiplesOf1 = 'MultiplesOf1', - /** - */ - MultiplesOf2 = 'MultiplesOf2', - /** - */ - MultiplesOf5 = 'MultiplesOf5', - /** - */ - MultiplesOf25 = 'MultiplesOf25', } \ No newline at end of file diff --git a/ffi/capi/bindings/js/FixedDecimalRoundingIncrement.mjs b/ffi/capi/bindings/js/FixedDecimalRoundingIncrement.mjs index 4f6527bddff..6bd40cbee69 100644 --- a/ffi/capi/bindings/js/FixedDecimalRoundingIncrement.mjs +++ b/ffi/capi/bindings/js/FixedDecimalRoundingIncrement.mjs @@ -1,23 +1,52 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" - -export const FixedDecimalRoundingIncrement_js_to_rust = { - "MultiplesOf1": 0, - "MultiplesOf2": 1, - "MultiplesOf5": 2, - "MultiplesOf25": 3, -}; - -export const FixedDecimalRoundingIncrement_rust_to_js = { - [0]: "MultiplesOf1", - [1]: "MultiplesOf2", - [2]: "MultiplesOf5", - [3]: "MultiplesOf25", -}; - -export const FixedDecimalRoundingIncrement = { - "MultiplesOf1": "MultiplesOf1", - "MultiplesOf2": "MultiplesOf2", - "MultiplesOf5": "MultiplesOf5", - "MultiplesOf25": "MultiplesOf25", -}; +// generated by diplomat-tool +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; + +// Base enumerator definition +/** Increment used in a rounding operation. +* +*See the [Rust documentation for `RoundingIncrement`](https://docs.rs/fixed_decimal/latest/fixed_decimal/enum.RoundingIncrement.html) for more information. +*/ +export class FixedDecimalRoundingIncrement { + #value = undefined; + + static values = new Map([ + ["MultiplesOf1", 0], + ["MultiplesOf2", 1], + ["MultiplesOf5", 2], + ["MultiplesOf25", 3] + ]); + constructor(value) { + if (value instanceof FixedDecimalRoundingIncrement) { + this.#value = value.value; + return; + } + + if (FixedDecimalRoundingIncrement.values.has(value)) { + this.#value = value; + return; + } + + throw TypeError(value + " is not a FixedDecimalRoundingIncrement and does not correspond to any of its enumerator values."); + } + + get value() { + return this.#value; + } + + get ffiValue() { + return FixedDecimalRoundingIncrement.values.get(this.#value); + } + + static MultiplesOf1 = new FixedDecimalRoundingIncrement("MultiplesOf1"); + + static MultiplesOf2 = new FixedDecimalRoundingIncrement("MultiplesOf2"); + + static MultiplesOf5 = new FixedDecimalRoundingIncrement("MultiplesOf5"); + + static MultiplesOf25 = new FixedDecimalRoundingIncrement("MultiplesOf25"); + + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/FixedDecimalRoundingMode.d.ts b/ffi/capi/bindings/js/FixedDecimalRoundingMode.d.ts index f1920a8fac6..21086c471be 100644 --- a/ffi/capi/bindings/js/FixedDecimalRoundingMode.d.ts +++ b/ffi/capi/bindings/js/FixedDecimalRoundingMode.d.ts @@ -1,36 +1,37 @@ +// generated by diplomat-tool +import type { pointer, char } from "./diplomat-runtime.d.ts"; + +// Base enumerator definition +/** Mode used in a rounding operation. +* +*See the [Rust documentation for `RoundingMode`](https://docs.rs/fixed_decimal/latest/fixed_decimal/enum.RoundingMode.html) for more information. +*/ +export class FixedDecimalRoundingMode { + constructor(value : FixedDecimalRoundingMode | string); + + get value() : string; + + get ffiValue() : number; + + static Ceil : FixedDecimalRoundingMode; + + static Expand : FixedDecimalRoundingMode; + + static Floor : FixedDecimalRoundingMode; + + static Trunc : FixedDecimalRoundingMode; + + static HalfCeil : FixedDecimalRoundingMode; + + static HalfExpand : FixedDecimalRoundingMode; + + static HalfFloor : FixedDecimalRoundingMode; + + static HalfTrunc : FixedDecimalRoundingMode; + + static HalfEven : FixedDecimalRoundingMode; + + + -/** - - * Mode used in a rounding operation. - - * See the {@link https://docs.rs/fixed_decimal/latest/fixed_decimal/enum.RoundingMode.html Rust documentation for `RoundingMode`} for more information. - */ -export enum FixedDecimalRoundingMode { - /** - */ - Ceil = 'Ceil', - /** - */ - Expand = 'Expand', - /** - */ - Floor = 'Floor', - /** - */ - Trunc = 'Trunc', - /** - */ - HalfCeil = 'HalfCeil', - /** - */ - HalfExpand = 'HalfExpand', - /** - */ - HalfFloor = 'HalfFloor', - /** - */ - HalfTrunc = 'HalfTrunc', - /** - */ - HalfEven = 'HalfEven', } \ No newline at end of file diff --git a/ffi/capi/bindings/js/FixedDecimalRoundingMode.mjs b/ffi/capi/bindings/js/FixedDecimalRoundingMode.mjs index ab24c615619..7c7f8732bed 100644 --- a/ffi/capi/bindings/js/FixedDecimalRoundingMode.mjs +++ b/ffi/capi/bindings/js/FixedDecimalRoundingMode.mjs @@ -1,38 +1,67 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" - -export const FixedDecimalRoundingMode_js_to_rust = { - "Ceil": 0, - "Expand": 1, - "Floor": 2, - "Trunc": 3, - "HalfCeil": 4, - "HalfExpand": 5, - "HalfFloor": 6, - "HalfTrunc": 7, - "HalfEven": 8, -}; - -export const FixedDecimalRoundingMode_rust_to_js = { - [0]: "Ceil", - [1]: "Expand", - [2]: "Floor", - [3]: "Trunc", - [4]: "HalfCeil", - [5]: "HalfExpand", - [6]: "HalfFloor", - [7]: "HalfTrunc", - [8]: "HalfEven", -}; - -export const FixedDecimalRoundingMode = { - "Ceil": "Ceil", - "Expand": "Expand", - "Floor": "Floor", - "Trunc": "Trunc", - "HalfCeil": "HalfCeil", - "HalfExpand": "HalfExpand", - "HalfFloor": "HalfFloor", - "HalfTrunc": "HalfTrunc", - "HalfEven": "HalfEven", -}; +// generated by diplomat-tool +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; + +// Base enumerator definition +/** Mode used in a rounding operation. +* +*See the [Rust documentation for `RoundingMode`](https://docs.rs/fixed_decimal/latest/fixed_decimal/enum.RoundingMode.html) for more information. +*/ +export class FixedDecimalRoundingMode { + #value = undefined; + + static values = new Map([ + ["Ceil", 0], + ["Expand", 1], + ["Floor", 2], + ["Trunc", 3], + ["HalfCeil", 4], + ["HalfExpand", 5], + ["HalfFloor", 6], + ["HalfTrunc", 7], + ["HalfEven", 8] + ]); + constructor(value) { + if (value instanceof FixedDecimalRoundingMode) { + this.#value = value.value; + return; + } + + if (FixedDecimalRoundingMode.values.has(value)) { + this.#value = value; + return; + } + + throw TypeError(value + " is not a FixedDecimalRoundingMode and does not correspond to any of its enumerator values."); + } + + get value() { + return this.#value; + } + + get ffiValue() { + return FixedDecimalRoundingMode.values.get(this.#value); + } + + static Ceil = new FixedDecimalRoundingMode("Ceil"); + + static Expand = new FixedDecimalRoundingMode("Expand"); + + static Floor = new FixedDecimalRoundingMode("Floor"); + + static Trunc = new FixedDecimalRoundingMode("Trunc"); + + static HalfCeil = new FixedDecimalRoundingMode("HalfCeil"); + + static HalfExpand = new FixedDecimalRoundingMode("HalfExpand"); + + static HalfFloor = new FixedDecimalRoundingMode("HalfFloor"); + + static HalfTrunc = new FixedDecimalRoundingMode("HalfTrunc"); + + static HalfEven = new FixedDecimalRoundingMode("HalfEven"); + + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/FixedDecimalSign.d.ts b/ffi/capi/bindings/js/FixedDecimalSign.d.ts index 22e974ed5d5..c64113fd6a3 100644 --- a/ffi/capi/bindings/js/FixedDecimalSign.d.ts +++ b/ffi/capi/bindings/js/FixedDecimalSign.d.ts @@ -1,24 +1,25 @@ +// generated by diplomat-tool +import type { pointer, char } from "./diplomat-runtime.d.ts"; -/** +// Base enumerator definition +/** The sign of a FixedDecimal, as shown in formatting. +* +*See the [Rust documentation for `Sign`](https://docs.rs/fixed_decimal/latest/fixed_decimal/enum.Sign.html) for more information. +*/ +export class FixedDecimalSign { + constructor(value : FixedDecimalSign | string); - * The sign of a FixedDecimal, as shown in formatting. + get value() : string; - * See the {@link https://docs.rs/fixed_decimal/latest/fixed_decimal/enum.Sign.html Rust documentation for `Sign`} for more information. - */ -export enum FixedDecimalSign { - /** + get ffiValue() : number; - * No sign (implicitly positive, e.g., 1729). - */ - None = 'None', - /** + static None : FixedDecimalSign; - * A negative sign, e.g., -1729. - */ - Negative = 'Negative', - /** + static Negative : FixedDecimalSign; + + static Positive : FixedDecimalSign; + + + - * An explicit positive sign, e.g., +1729. - */ - Positive = 'Positive', } \ No newline at end of file diff --git a/ffi/capi/bindings/js/FixedDecimalSign.mjs b/ffi/capi/bindings/js/FixedDecimalSign.mjs index 123a6ada78e..a4b07cfb020 100644 --- a/ffi/capi/bindings/js/FixedDecimalSign.mjs +++ b/ffi/capi/bindings/js/FixedDecimalSign.mjs @@ -1,20 +1,49 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" - -export const FixedDecimalSign_js_to_rust = { - "None": 0, - "Negative": 1, - "Positive": 2, -}; - -export const FixedDecimalSign_rust_to_js = { - [0]: "None", - [1]: "Negative", - [2]: "Positive", -}; - -export const FixedDecimalSign = { - "None": "None", - "Negative": "Negative", - "Positive": "Positive", -}; +// generated by diplomat-tool +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; + +// Base enumerator definition +/** The sign of a FixedDecimal, as shown in formatting. +* +*See the [Rust documentation for `Sign`](https://docs.rs/fixed_decimal/latest/fixed_decimal/enum.Sign.html) for more information. +*/ +export class FixedDecimalSign { + #value = undefined; + + static values = new Map([ + ["None", 0], + ["Negative", 1], + ["Positive", 2] + ]); + constructor(value) { + if (value instanceof FixedDecimalSign) { + this.#value = value.value; + return; + } + + if (FixedDecimalSign.values.has(value)) { + this.#value = value; + return; + } + + throw TypeError(value + " is not a FixedDecimalSign and does not correspond to any of its enumerator values."); + } + + get value() { + return this.#value; + } + + get ffiValue() { + return FixedDecimalSign.values.get(this.#value); + } + + static None = new FixedDecimalSign("None"); + + static Negative = new FixedDecimalSign("Negative"); + + static Positive = new FixedDecimalSign("Positive"); + + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/FixedDecimalSignDisplay.d.ts b/ffi/capi/bindings/js/FixedDecimalSignDisplay.d.ts index 175e6c42265..1164b1a6a9f 100644 --- a/ffi/capi/bindings/js/FixedDecimalSignDisplay.d.ts +++ b/ffi/capi/bindings/js/FixedDecimalSignDisplay.d.ts @@ -1,24 +1,29 @@ +// generated by diplomat-tool +import type { pointer, char } from "./diplomat-runtime.d.ts"; + +// Base enumerator definition +/** ECMA-402 compatible sign display preference. +* +*See the [Rust documentation for `SignDisplay`](https://docs.rs/fixed_decimal/latest/fixed_decimal/enum.SignDisplay.html) for more information. +*/ +export class FixedDecimalSignDisplay { + constructor(value : FixedDecimalSignDisplay | string); + + get value() : string; + + get ffiValue() : number; + + static Auto : FixedDecimalSignDisplay; + + static Never : FixedDecimalSignDisplay; + + static Always : FixedDecimalSignDisplay; + + static ExceptZero : FixedDecimalSignDisplay; + + static Negative : FixedDecimalSignDisplay; + + + -/** - - * ECMA-402 compatible sign display preference. - - * See the {@link https://docs.rs/fixed_decimal/latest/fixed_decimal/enum.SignDisplay.html Rust documentation for `SignDisplay`} for more information. - */ -export enum FixedDecimalSignDisplay { - /** - */ - Auto = 'Auto', - /** - */ - Never = 'Never', - /** - */ - Always = 'Always', - /** - */ - ExceptZero = 'ExceptZero', - /** - */ - Negative = 'Negative', } \ No newline at end of file diff --git a/ffi/capi/bindings/js/FixedDecimalSignDisplay.mjs b/ffi/capi/bindings/js/FixedDecimalSignDisplay.mjs index 72af6d774e3..a398a07858e 100644 --- a/ffi/capi/bindings/js/FixedDecimalSignDisplay.mjs +++ b/ffi/capi/bindings/js/FixedDecimalSignDisplay.mjs @@ -1,26 +1,55 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" - -export const FixedDecimalSignDisplay_js_to_rust = { - "Auto": 0, - "Never": 1, - "Always": 2, - "ExceptZero": 3, - "Negative": 4, -}; - -export const FixedDecimalSignDisplay_rust_to_js = { - [0]: "Auto", - [1]: "Never", - [2]: "Always", - [3]: "ExceptZero", - [4]: "Negative", -}; - -export const FixedDecimalSignDisplay = { - "Auto": "Auto", - "Never": "Never", - "Always": "Always", - "ExceptZero": "ExceptZero", - "Negative": "Negative", -}; +// generated by diplomat-tool +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; + +// Base enumerator definition +/** ECMA-402 compatible sign display preference. +* +*See the [Rust documentation for `SignDisplay`](https://docs.rs/fixed_decimal/latest/fixed_decimal/enum.SignDisplay.html) for more information. +*/ +export class FixedDecimalSignDisplay { + #value = undefined; + + static values = new Map([ + ["Auto", 0], + ["Never", 1], + ["Always", 2], + ["ExceptZero", 3], + ["Negative", 4] + ]); + constructor(value) { + if (value instanceof FixedDecimalSignDisplay) { + this.#value = value.value; + return; + } + + if (FixedDecimalSignDisplay.values.has(value)) { + this.#value = value; + return; + } + + throw TypeError(value + " is not a FixedDecimalSignDisplay and does not correspond to any of its enumerator values."); + } + + get value() { + return this.#value; + } + + get ffiValue() { + return FixedDecimalSignDisplay.values.get(this.#value); + } + + static Auto = new FixedDecimalSignDisplay("Auto"); + + static Never = new FixedDecimalSignDisplay("Never"); + + static Always = new FixedDecimalSignDisplay("Always"); + + static ExceptZero = new FixedDecimalSignDisplay("ExceptZero"); + + static Negative = new FixedDecimalSignDisplay("Negative"); + + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/GeneralCategoryNameToMaskMapper.d.ts b/ffi/capi/bindings/js/GeneralCategoryNameToMaskMapper.d.ts index 6961ba95cf6..ac81961aae5 100644 --- a/ffi/capi/bindings/js/GeneralCategoryNameToMaskMapper.d.ts +++ b/ffi/capi/bindings/js/GeneralCategoryNameToMaskMapper.d.ts @@ -1,38 +1,26 @@ -import { u32 } from "./diplomat-runtime" -import { FFIError } from "./diplomat-runtime" -import { DataError } from "./DataError"; -import { DataProvider } from "./DataProvider"; +// generated by diplomat-tool +import type { DataProvider } from "./DataProvider" +import type { pointer, char } from "./diplomat-runtime.d.ts"; -/** - * A type capable of looking up General Category mask values from a string name. - - * See the {@link https://docs.rs/icu/latest/icu/properties/struct.GeneralCategoryGroup.html#method.name_to_enum_mapper Rust documentation for `name_to_enum_mapper`} for more information. - - * See the {@link https://docs.rs/icu/latest/icu/properties/names/struct.PropertyValueNameToEnumMapper.html Rust documentation for `PropertyValueNameToEnumMapper`} for more information. - */ +/** A type capable of looking up General Category mask values from a string name. +* +*See the [Rust documentation for `name_to_enum_mapper`](https://docs.rs/icu/latest/icu/properties/struct.GeneralCategoryGroup.html#method.name_to_enum_mapper) for more information. +* +*See the [Rust documentation for `PropertyValueNameToEnumMapper`](https://docs.rs/icu/latest/icu/properties/names/struct.PropertyValueNameToEnumMapper.html) for more information. +*/ export class GeneralCategoryNameToMaskMapper { + - /** - - * Get the mask value matching the given name, using strict matching + get ffiValue(): pointer; - * Returns 0 if the name is unknown for this property - */ - get_strict(name: string): u32; - /** + getStrict(name: string): number; - * Get the mask value matching the given name, using loose matching + getLoose(name: string): number; - * Returns 0 if the name is unknown for this property - */ - get_loose(name: string): u32; + static load(provider: DataProvider): GeneralCategoryNameToMaskMapper; - /** + - * See the {@link https://docs.rs/icu/latest/icu/properties/struct.GeneralCategoryGroup.html#method.name_to_enum_mapper Rust documentation for `name_to_enum_mapper`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load(provider: DataProvider): GeneralCategoryNameToMaskMapper | never; -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/GeneralCategoryNameToMaskMapper.mjs b/ffi/capi/bindings/js/GeneralCategoryNameToMaskMapper.mjs index 151e3b5ca2a..e40323b3d30 100644 --- a/ffi/capi/bindings/js/GeneralCategoryNameToMaskMapper.mjs +++ b/ffi/capi/bindings/js/GeneralCategoryNameToMaskMapper.mjs @@ -1,49 +1,91 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" -import { DataError_js_to_rust, DataError_rust_to_js } from "./DataError.mjs" +// generated by diplomat-tool +import { DataError } from "./DataError.mjs" +import { DataProvider } from "./DataProvider.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -const GeneralCategoryNameToMaskMapper_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XGeneralCategoryNameToMaskMapper_destroy(underlying); -}); +/** A type capable of looking up General Category mask values from a string name. +* +*See the [Rust documentation for `name_to_enum_mapper`](https://docs.rs/icu/latest/icu/properties/struct.GeneralCategoryGroup.html#method.name_to_enum_mapper) for more information. +* +*See the [Rust documentation for `PropertyValueNameToEnumMapper`](https://docs.rs/icu/latest/icu/properties/names/struct.PropertyValueNameToEnumMapper.html) for more information. +*/ + +const GeneralCategoryNameToMaskMapper_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XGeneralCategoryNameToMaskMapper_destroy(ptr); +}); export class GeneralCategoryNameToMaskMapper { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - GeneralCategoryNameToMaskMapper_box_destroy_registry.register(this, underlying); + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + + constructor(ptr, selfEdge) { + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + GeneralCategoryNameToMaskMapper_box_destroy_registry.register(this, this.#ptr); } - } - - get_strict(arg_name) { - const buf_arg_name = diplomatRuntime.DiplomatBuf.str8(wasm, arg_name); - const diplomat_out = wasm.ICU4XGeneralCategoryNameToMaskMapper_get_strict(this.underlying, buf_arg_name.ptr, buf_arg_name.size); - buf_arg_name.free(); - return diplomat_out; - } - - get_loose(arg_name) { - const buf_arg_name = diplomatRuntime.DiplomatBuf.str8(wasm, arg_name); - const diplomat_out = wasm.ICU4XGeneralCategoryNameToMaskMapper_get_loose(this.underlying, buf_arg_name.ptr, buf_arg_name.size); - buf_arg_name.free(); - return diplomat_out; - } - - static load(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XGeneralCategoryNameToMaskMapper_load(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new GeneralCategoryNameToMaskMapper(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } -} + + get ffiValue() { + return this.#ptr; + } + + + getStrict(name) { + + const nameSlice = diplomatRuntime.DiplomatBuf.str8(wasm, name); + const result = wasm.ICU4XGeneralCategoryNameToMaskMapper_get_strict(this.ffiValue, nameSlice.ptr, nameSlice.size); + + try { + + return result; + } finally { + + nameSlice.free(); + + } + } + + getLoose(name) { + + const nameSlice = diplomatRuntime.DiplomatBuf.str8(wasm, name); + const result = wasm.ICU4XGeneralCategoryNameToMaskMapper_get_loose(this.ffiValue, nameSlice.ptr, nameSlice.size); + + try { + + return result; + } finally { + + nameSlice.free(); + + } + } + + static load(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XGeneralCategoryNameToMaskMapper_load(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new GeneralCategoryNameToMaskMapper(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/GraphemeClusterBreakIteratorLatin1.d.ts b/ffi/capi/bindings/js/GraphemeClusterBreakIteratorLatin1.d.ts index 3c0816b9762..783c47bfd55 100644 --- a/ffi/capi/bindings/js/GraphemeClusterBreakIteratorLatin1.d.ts +++ b/ffi/capi/bindings/js/GraphemeClusterBreakIteratorLatin1.d.ts @@ -1,16 +1,17 @@ -import { i32 } from "./diplomat-runtime" +// generated by diplomat-tool +import type { pointer, char } from "./diplomat-runtime.d.ts"; -/** - * See the {@link https://docs.rs/icu/latest/icu/segmenter/struct.GraphemeClusterBreakIterator.html Rust documentation for `GraphemeClusterBreakIterator`} for more information. - */ +/** See the [Rust documentation for `GraphemeClusterBreakIterator`](https://docs.rs/icu/latest/icu/segmenter/struct.GraphemeClusterBreakIterator.html) for more information. +*/ export class GraphemeClusterBreakIteratorLatin1 { + - /** + get ffiValue(): pointer; - * Finds the next breakpoint. Returns -1 if at the end of the string or if the index is out of range of a 32-bit signed integer. - * See the {@link https://docs.rs/icu/latest/icu/segmenter/struct.GraphemeClusterBreakIterator.html#method.next Rust documentation for `next`} for more information. - */ - next(): i32; -} + next(): number; + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/GraphemeClusterBreakIteratorLatin1.mjs b/ffi/capi/bindings/js/GraphemeClusterBreakIteratorLatin1.mjs index 83920ea724e..88b9eb05da9 100644 --- a/ffi/capi/bindings/js/GraphemeClusterBreakIteratorLatin1.mjs +++ b/ffi/capi/bindings/js/GraphemeClusterBreakIteratorLatin1.mjs @@ -1,21 +1,52 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" +// generated by diplomat-tool +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -const GraphemeClusterBreakIteratorLatin1_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XGraphemeClusterBreakIteratorLatin1_destroy(underlying); -}); +/** See the [Rust documentation for `GraphemeClusterBreakIterator`](https://docs.rs/icu/latest/icu/segmenter/struct.GraphemeClusterBreakIterator.html) for more information. +*/ + +const GraphemeClusterBreakIteratorLatin1_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XGraphemeClusterBreakIteratorLatin1_destroy(ptr); +}); export class GraphemeClusterBreakIteratorLatin1 { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - GraphemeClusterBreakIteratorLatin1_box_destroy_registry.register(this, underlying); + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + #aEdge = []; + + + constructor(ptr, selfEdge, aEdge) { + + + this.#aEdge = aEdge; + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + GraphemeClusterBreakIteratorLatin1_box_destroy_registry.register(this, this.#ptr); + } + + get ffiValue() { + return this.#ptr; } - } - next() { - return wasm.ICU4XGraphemeClusterBreakIteratorLatin1_next(this.underlying); - } -} + + next() { + const result = wasm.ICU4XGraphemeClusterBreakIteratorLatin1_next(this.ffiValue); + + try { + + return result; + } finally { + + } + } + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/GraphemeClusterBreakIteratorUtf16.d.ts b/ffi/capi/bindings/js/GraphemeClusterBreakIteratorUtf16.d.ts index f7f8f935aa2..826fb757dec 100644 --- a/ffi/capi/bindings/js/GraphemeClusterBreakIteratorUtf16.d.ts +++ b/ffi/capi/bindings/js/GraphemeClusterBreakIteratorUtf16.d.ts @@ -1,16 +1,17 @@ -import { i32 } from "./diplomat-runtime" +// generated by diplomat-tool +import type { pointer, char } from "./diplomat-runtime.d.ts"; -/** - * See the {@link https://docs.rs/icu/latest/icu/segmenter/struct.GraphemeClusterBreakIterator.html Rust documentation for `GraphemeClusterBreakIterator`} for more information. - */ +/** See the [Rust documentation for `GraphemeClusterBreakIterator`](https://docs.rs/icu/latest/icu/segmenter/struct.GraphemeClusterBreakIterator.html) for more information. +*/ export class GraphemeClusterBreakIteratorUtf16 { + - /** + get ffiValue(): pointer; - * Finds the next breakpoint. Returns -1 if at the end of the string or if the index is out of range of a 32-bit signed integer. - * See the {@link https://docs.rs/icu/latest/icu/segmenter/struct.GraphemeClusterBreakIterator.html#method.next Rust documentation for `next`} for more information. - */ - next(): i32; -} + next(): number; + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/GraphemeClusterBreakIteratorUtf16.mjs b/ffi/capi/bindings/js/GraphemeClusterBreakIteratorUtf16.mjs index 439db7ac043..096ead43754 100644 --- a/ffi/capi/bindings/js/GraphemeClusterBreakIteratorUtf16.mjs +++ b/ffi/capi/bindings/js/GraphemeClusterBreakIteratorUtf16.mjs @@ -1,21 +1,52 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" +// generated by diplomat-tool +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -const GraphemeClusterBreakIteratorUtf16_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XGraphemeClusterBreakIteratorUtf16_destroy(underlying); -}); +/** See the [Rust documentation for `GraphemeClusterBreakIterator`](https://docs.rs/icu/latest/icu/segmenter/struct.GraphemeClusterBreakIterator.html) for more information. +*/ + +const GraphemeClusterBreakIteratorUtf16_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XGraphemeClusterBreakIteratorUtf16_destroy(ptr); +}); export class GraphemeClusterBreakIteratorUtf16 { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - GraphemeClusterBreakIteratorUtf16_box_destroy_registry.register(this, underlying); + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + #aEdge = []; + + + constructor(ptr, selfEdge, aEdge) { + + + this.#aEdge = aEdge; + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + GraphemeClusterBreakIteratorUtf16_box_destroy_registry.register(this, this.#ptr); + } + + get ffiValue() { + return this.#ptr; } - } - next() { - return wasm.ICU4XGraphemeClusterBreakIteratorUtf16_next(this.underlying); - } -} + + next() { + const result = wasm.ICU4XGraphemeClusterBreakIteratorUtf16_next(this.ffiValue); + + try { + + return result; + } finally { + + } + } + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/GraphemeClusterBreakIteratorUtf8.d.ts b/ffi/capi/bindings/js/GraphemeClusterBreakIteratorUtf8.d.ts index b945fe3b74f..c423d36b426 100644 --- a/ffi/capi/bindings/js/GraphemeClusterBreakIteratorUtf8.d.ts +++ b/ffi/capi/bindings/js/GraphemeClusterBreakIteratorUtf8.d.ts @@ -1,16 +1,17 @@ -import { i32 } from "./diplomat-runtime" +// generated by diplomat-tool +import type { pointer, char } from "./diplomat-runtime.d.ts"; -/** - * See the {@link https://docs.rs/icu/latest/icu/segmenter/struct.GraphemeClusterBreakIterator.html Rust documentation for `GraphemeClusterBreakIterator`} for more information. - */ +/** See the [Rust documentation for `GraphemeClusterBreakIterator`](https://docs.rs/icu/latest/icu/segmenter/struct.GraphemeClusterBreakIterator.html) for more information. +*/ export class GraphemeClusterBreakIteratorUtf8 { + - /** + get ffiValue(): pointer; - * Finds the next breakpoint. Returns -1 if at the end of the string or if the index is out of range of a 32-bit signed integer. - * See the {@link https://docs.rs/icu/latest/icu/segmenter/struct.GraphemeClusterBreakIterator.html#method.next Rust documentation for `next`} for more information. - */ - next(): i32; -} + next(): number; + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/GraphemeClusterBreakIteratorUtf8.mjs b/ffi/capi/bindings/js/GraphemeClusterBreakIteratorUtf8.mjs index 21602e2464c..3c69ba70f8e 100644 --- a/ffi/capi/bindings/js/GraphemeClusterBreakIteratorUtf8.mjs +++ b/ffi/capi/bindings/js/GraphemeClusterBreakIteratorUtf8.mjs @@ -1,21 +1,52 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" +// generated by diplomat-tool +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -const GraphemeClusterBreakIteratorUtf8_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XGraphemeClusterBreakIteratorUtf8_destroy(underlying); -}); +/** See the [Rust documentation for `GraphemeClusterBreakIterator`](https://docs.rs/icu/latest/icu/segmenter/struct.GraphemeClusterBreakIterator.html) for more information. +*/ + +const GraphemeClusterBreakIteratorUtf8_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XGraphemeClusterBreakIteratorUtf8_destroy(ptr); +}); export class GraphemeClusterBreakIteratorUtf8 { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - GraphemeClusterBreakIteratorUtf8_box_destroy_registry.register(this, underlying); + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + #aEdge = []; + + + constructor(ptr, selfEdge, aEdge) { + + + this.#aEdge = aEdge; + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + GraphemeClusterBreakIteratorUtf8_box_destroy_registry.register(this, this.#ptr); + } + + get ffiValue() { + return this.#ptr; } - } - next() { - return wasm.ICU4XGraphemeClusterBreakIteratorUtf8_next(this.underlying); - } -} + + next() { + const result = wasm.ICU4XGraphemeClusterBreakIteratorUtf8_next(this.ffiValue); + + try { + + return result; + } finally { + + } + } + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/GraphemeClusterSegmenter.d.ts b/ffi/capi/bindings/js/GraphemeClusterSegmenter.d.ts index 44f34e430a7..6e414a0532e 100644 --- a/ffi/capi/bindings/js/GraphemeClusterSegmenter.d.ts +++ b/ffi/capi/bindings/js/GraphemeClusterSegmenter.d.ts @@ -1,52 +1,24 @@ -import { FFIError } from "./diplomat-runtime" -import { DataError } from "./DataError"; -import { DataProvider } from "./DataProvider"; -import { GraphemeClusterBreakIteratorLatin1 } from "./GraphemeClusterBreakIteratorLatin1"; -import { GraphemeClusterBreakIteratorUtf16 } from "./GraphemeClusterBreakIteratorUtf16"; -import { GraphemeClusterBreakIteratorUtf8 } from "./GraphemeClusterBreakIteratorUtf8"; +// generated by diplomat-tool +import type { DataProvider } from "./DataProvider" +import type { GraphemeClusterBreakIteratorUtf16 } from "./GraphemeClusterBreakIteratorUtf16" +import type { pointer, char } from "./diplomat-runtime.d.ts"; -/** - * An ICU4X grapheme-cluster-break segmenter, capable of finding grapheme cluster breakpoints in strings. - - * See the {@link https://docs.rs/icu/latest/icu/segmenter/struct.GraphemeClusterSegmenter.html Rust documentation for `GraphemeClusterSegmenter`} for more information. - */ +/** An ICU4X grapheme-cluster-break segmenter, capable of finding grapheme cluster breakpoints +*in strings. +* +*See the [Rust documentation for `GraphemeClusterSegmenter`](https://docs.rs/icu/latest/icu/segmenter/struct.GraphemeClusterSegmenter.html) for more information. +*/ export class GraphemeClusterSegmenter { + - /** - - * Construct an {@link GraphemeClusterSegmenter `GraphemeClusterSegmenter`}. - - * See the {@link https://docs.rs/icu/latest/icu/segmenter/struct.GraphemeClusterSegmenter.html#method.new Rust documentation for `new`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static create(provider: DataProvider): GraphemeClusterSegmenter | never; - - /** - - * Segments a string. - - * Ill-formed input is treated as if errors had been replaced with REPLACEMENT CHARACTERs according to the WHATWG Encoding Standard. - - * See the {@link https://docs.rs/icu/latest/icu/segmenter/struct.GraphemeClusterSegmenter.html#method.segment_utf8 Rust documentation for `segment_utf8`} for more information. - */ - segment_utf8(input: string): GraphemeClusterBreakIteratorUtf8; - - /** - - * Segments a string. + get ffiValue(): pointer; - * Ill-formed input is treated as if errors had been replaced with REPLACEMENT CHARACTERs according to the WHATWG Encoding Standard. - * See the {@link https://docs.rs/icu/latest/icu/segmenter/struct.GraphemeClusterSegmenter.html#method.segment_utf16 Rust documentation for `segment_utf16`} for more information. - */ - segment_utf16(input: string): GraphemeClusterBreakIteratorUtf16; + static create(provider: DataProvider): GraphemeClusterSegmenter; - /** + segment(input: string): GraphemeClusterBreakIteratorUtf16; - * Segments a Latin-1 string. + - * See the {@link https://docs.rs/icu/latest/icu/segmenter/struct.GraphemeClusterSegmenter.html#method.segment_latin1 Rust documentation for `segment_latin1`} for more information. - */ - segment_latin1(input: Uint8Array): GraphemeClusterBreakIteratorLatin1; -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/GraphemeClusterSegmenter.mjs b/ffi/capi/bindings/js/GraphemeClusterSegmenter.mjs index 2dd27e96c20..8a13c9b3132 100644 --- a/ffi/capi/bindings/js/GraphemeClusterSegmenter.mjs +++ b/ffi/capi/bindings/js/GraphemeClusterSegmenter.mjs @@ -1,59 +1,79 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" -import { DataError_js_to_rust, DataError_rust_to_js } from "./DataError.mjs" -import { GraphemeClusterBreakIteratorLatin1 } from "./GraphemeClusterBreakIteratorLatin1.mjs" +// generated by diplomat-tool +import { DataError } from "./DataError.mjs" +import { DataProvider } from "./DataProvider.mjs" import { GraphemeClusterBreakIteratorUtf16 } from "./GraphemeClusterBreakIteratorUtf16.mjs" -import { GraphemeClusterBreakIteratorUtf8 } from "./GraphemeClusterBreakIteratorUtf8.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -const GraphemeClusterSegmenter_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XGraphemeClusterSegmenter_destroy(underlying); -}); +/** An ICU4X grapheme-cluster-break segmenter, capable of finding grapheme cluster breakpoints +*in strings. +* +*See the [Rust documentation for `GraphemeClusterSegmenter`](https://docs.rs/icu/latest/icu/segmenter/struct.GraphemeClusterSegmenter.html) for more information. +*/ + +const GraphemeClusterSegmenter_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XGraphemeClusterSegmenter_destroy(ptr); +}); export class GraphemeClusterSegmenter { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - GraphemeClusterSegmenter_box_destroy_registry.register(this, underlying); + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + + constructor(ptr, selfEdge) { + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + GraphemeClusterSegmenter_box_destroy_registry.register(this, this.#ptr); } - } - - static create(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XGraphemeClusterSegmenter_create(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new GraphemeClusterSegmenter(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - segment_utf8(arg_input) { - const buf_arg_input = diplomatRuntime.DiplomatBuf.str8(wasm, arg_input); - const diplomat_out = new GraphemeClusterBreakIteratorUtf8(wasm.ICU4XGraphemeClusterSegmenter_segment_utf8(this.underlying, buf_arg_input.ptr, buf_arg_input.size), true, [this, buf_arg_input]); - buf_arg_input.garbageCollect(); - return diplomat_out; - } - - segment_utf16(arg_input) { - const buf_arg_input = diplomatRuntime.DiplomatBuf.str16(wasm, arg_input); - const diplomat_out = new GraphemeClusterBreakIteratorUtf16(wasm.ICU4XGraphemeClusterSegmenter_segment_utf16(this.underlying, buf_arg_input.ptr, buf_arg_input.size), true, [this, buf_arg_input]); - buf_arg_input.garbageCollect(); - return diplomat_out; - } - - segment_latin1(arg_input) { - const buf_arg_input = diplomatRuntime.DiplomatBuf.slice(wasm, arg_input, "u8"); - const diplomat_out = new GraphemeClusterBreakIteratorLatin1(wasm.ICU4XGraphemeClusterSegmenter_segment_latin1(this.underlying, buf_arg_input.ptr, buf_arg_input.size), true, [this, buf_arg_input]); - buf_arg_input.garbageCollect(); - return diplomat_out; - } -} + + get ffiValue() { + return this.#ptr; + } + + + static create(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XGraphemeClusterSegmenter_create(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new GraphemeClusterSegmenter(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + segment(input) { + + const inputSlice = diplomatRuntime.DiplomatBuf.str16(wasm, input); + + // This lifetime edge depends on lifetimes 'a + let aEdges = [this, inputSlice]; + const result = wasm.ICU4XGraphemeClusterSegmenter_segment_utf16(this.ffiValue, inputSlice.ptr, inputSlice.size); + + try { + + return new GraphemeClusterBreakIteratorUtf16(result, [], aEdges); + } finally { + + inputSlice.garbageCollect(); + + } + } + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/GregorianDateFormatter.d.ts b/ffi/capi/bindings/js/GregorianDateFormatter.d.ts index ea37b79832d..92104e4bd0e 100644 --- a/ffi/capi/bindings/js/GregorianDateFormatter.d.ts +++ b/ffi/capi/bindings/js/GregorianDateFormatter.d.ts @@ -1,41 +1,29 @@ -import { FFIError } from "./diplomat-runtime" -import { DataProvider } from "./DataProvider"; -import { DateLength } from "./DateLength"; -import { Error } from "./Error"; -import { IsoDate } from "./IsoDate"; -import { IsoDateTime } from "./IsoDateTime"; -import { Locale } from "./Locale"; - -/** - - * An ICU4X TypedDateFormatter object capable of formatting a {@link IsoDateTime `IsoDateTime`} as a string, using the Gregorian Calendar. - - * See the {@link https://docs.rs/icu/latest/icu/datetime/struct.TypedDateFormatter.html Rust documentation for `TypedDateFormatter`} for more information. - */ +// generated by diplomat-tool +import type { DataProvider } from "./DataProvider" +import type { DateLength } from "./DateLength" +import type { IsoDate } from "./IsoDate" +import type { IsoDateTime } from "./IsoDateTime" +import type { Locale } from "./Locale" +import type { pointer, char } from "./diplomat-runtime.d.ts"; + + +/** An ICU4X TypedDateFormatter object capable of formatting a [`IsoDateTime`] as a string, +*using the Gregorian Calendar. +* +*See the [Rust documentation for `TypedDateFormatter`](https://docs.rs/icu/latest/icu/datetime/struct.TypedDateFormatter.html) for more information. +*/ export class GregorianDateFormatter { + - /** - - * Creates a new {@link GregorianDateFormatter `GregorianDateFormatter`} from locale data. - - * See the {@link https://docs.rs/icu/latest/icu/datetime/struct.TypedDateFormatter.html#method.try_new_with_length Rust documentation for `try_new_with_length`} for more information. - * @throws {@link FFIError}<{@link Error}> - */ - static create_with_length(provider: DataProvider, locale: Locale, length: DateLength): GregorianDateFormatter | never; + get ffiValue(): pointer; - /** - * Formats a {@link IsoDate `IsoDate`} to a string. + static createWithLength(provider: DataProvider, locale: Locale, length: DateLength): GregorianDateFormatter; - * See the {@link https://docs.rs/icu/latest/icu/datetime/struct.TypedDateFormatter.html#method.format Rust documentation for `format`} for more information. - */ - format_iso_date(value: IsoDate): string; + formatIsoDate(value: IsoDate): string; - /** + formatIsoDatetime(value: IsoDateTime): string; - * Formats a {@link IsoDateTime `IsoDateTime`} to a string. + - * See the {@link https://docs.rs/icu/latest/icu/datetime/struct.TypedDateFormatter.html#method.format Rust documentation for `format`} for more information. - */ - format_iso_datetime(value: IsoDateTime): string; -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/GregorianDateFormatter.mjs b/ffi/capi/bindings/js/GregorianDateFormatter.mjs index 0cc15d2ea4e..f1556fb1506 100644 --- a/ffi/capi/bindings/js/GregorianDateFormatter.mjs +++ b/ffi/capi/bindings/js/GregorianDateFormatter.mjs @@ -1,48 +1,94 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" -import { DateLength_js_to_rust, DateLength_rust_to_js } from "./DateLength.mjs" -import { Error_js_to_rust, Error_rust_to_js } from "./Error.mjs" +// generated by diplomat-tool +import { DataProvider } from "./DataProvider.mjs" +import { DateLength } from "./DateLength.mjs" +import { Error } from "./Error.mjs" +import { IsoDate } from "./IsoDate.mjs" +import { IsoDateTime } from "./IsoDateTime.mjs" +import { Locale } from "./Locale.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -const GregorianDateFormatter_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XGregorianDateFormatter_destroy(underlying); -}); +/** An ICU4X TypedDateFormatter object capable of formatting a [`IsoDateTime`] as a string, +*using the Gregorian Calendar. +* +*See the [Rust documentation for `TypedDateFormatter`](https://docs.rs/icu/latest/icu/datetime/struct.TypedDateFormatter.html) for more information. +*/ + +const GregorianDateFormatter_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XGregorianDateFormatter_destroy(ptr); +}); export class GregorianDateFormatter { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - GregorianDateFormatter_box_destroy_registry.register(this, underlying); + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + + constructor(ptr, selfEdge) { + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + GregorianDateFormatter_box_destroy_registry.register(this, this.#ptr); } - } - - static create_with_length(arg_provider, arg_locale, arg_length) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XGregorianDateFormatter_create_with_length(diplomat_receive_buffer, arg_provider.underlying, arg_locale.underlying, DateLength_js_to_rust[arg_length]); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new GregorianDateFormatter(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = Error_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - format_iso_date(arg_value) { - return diplomatRuntime.withDiplomatWrite(wasm, (write) => { - return wasm.ICU4XGregorianDateFormatter_format_iso_date(this.underlying, arg_value.underlying, write); - }); - } - - format_iso_datetime(arg_value) { - return diplomatRuntime.withDiplomatWrite(wasm, (write) => { - return wasm.ICU4XGregorianDateFormatter_format_iso_datetime(this.underlying, arg_value.underlying, write); - }); - } -} + + get ffiValue() { + return this.#ptr; + } + + + static createWithLength(provider, locale, length) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XGregorianDateFormatter_create_with_length(diplomat_receive_buffer, provider.ffiValue, locale.ffiValue, length.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = (() => {for (let i of Error.values) { if(i[1] === diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)) return Error[i[0]]; } return null;})(); + throw new Error('Error: ' + cause.value, { cause }); + } + return new GregorianDateFormatter(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + formatIsoDate(value) { + + const write = wasm.diplomat_buffer_write_create(0); + wasm.ICU4XGregorianDateFormatter_format_iso_date(this.ffiValue, value.ffiValue, write); + + try { + + return diplomatRuntime.readString8(wasm, wasm.diplomat_buffer_write_get_bytes(write), wasm.diplomat_buffer_write_len(write)); + } finally { + + wasm.diplomat_buffer_write_destroy(write); + + } + } + + formatIsoDatetime(value) { + + const write = wasm.diplomat_buffer_write_create(0); + wasm.ICU4XGregorianDateFormatter_format_iso_datetime(this.ffiValue, value.ffiValue, write); + + try { + + return diplomatRuntime.readString8(wasm, wasm.diplomat_buffer_write_get_bytes(write), wasm.diplomat_buffer_write_len(write)); + } finally { + + wasm.diplomat_buffer_write_destroy(write); + + } + } + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/GregorianDateTimeFormatter.d.ts b/ffi/capi/bindings/js/GregorianDateTimeFormatter.d.ts index a777bdfea1e..853af9db20b 100644 --- a/ffi/capi/bindings/js/GregorianDateTimeFormatter.d.ts +++ b/ffi/capi/bindings/js/GregorianDateTimeFormatter.d.ts @@ -1,33 +1,27 @@ -import { FFIError } from "./diplomat-runtime" -import { DataProvider } from "./DataProvider"; -import { DateLength } from "./DateLength"; -import { Error } from "./Error"; -import { IsoDateTime } from "./IsoDateTime"; -import { Locale } from "./Locale"; -import { TimeLength } from "./TimeLength"; - -/** - - * An ICU4X TypedDateTimeFormatter object capable of formatting a {@link IsoDateTime `IsoDateTime`} as a string, using the Gregorian Calendar. - - * See the {@link https://docs.rs/icu/latest/icu/datetime/struct.TypedDateTimeFormatter.html Rust documentation for `TypedDateTimeFormatter`} for more information. - */ +// generated by diplomat-tool +import type { DataProvider } from "./DataProvider" +import type { DateLength } from "./DateLength" +import type { IsoDateTime } from "./IsoDateTime" +import type { Locale } from "./Locale" +import type { TimeLength } from "./TimeLength" +import type { pointer, char } from "./diplomat-runtime.d.ts"; + + +/** An ICU4X TypedDateTimeFormatter object capable of formatting a [`IsoDateTime`] as a string, +*using the Gregorian Calendar. +* +*See the [Rust documentation for `TypedDateTimeFormatter`](https://docs.rs/icu/latest/icu/datetime/struct.TypedDateTimeFormatter.html) for more information. +*/ export class GregorianDateTimeFormatter { + - /** + get ffiValue(): pointer; - * Creates a new {@link GregorianDateFormatter `GregorianDateFormatter`} from locale data. - * See the {@link https://docs.rs/icu/latest/icu/datetime/struct.TypedDateTimeFormatter.html#method.try_new Rust documentation for `try_new`} for more information. - * @throws {@link FFIError}<{@link Error}> - */ - static create_with_lengths(provider: DataProvider, locale: Locale, date_length: DateLength, time_length: TimeLength): GregorianDateTimeFormatter | never; + static createWithLengths(provider: DataProvider, locale: Locale, dateLength: DateLength, timeLength: TimeLength): GregorianDateTimeFormatter; - /** + formatIsoDatetime(value: IsoDateTime): string; - * Formats a {@link IsoDateTime `IsoDateTime`} to a string. + - * See the {@link https://docs.rs/icu/latest/icu/datetime/struct.TypedDateTimeFormatter.html#method.format Rust documentation for `format`} for more information. - */ - format_iso_datetime(value: IsoDateTime): string; -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/GregorianDateTimeFormatter.mjs b/ffi/capi/bindings/js/GregorianDateTimeFormatter.mjs index 3ee849b1f2d..ee58cadc54b 100644 --- a/ffi/capi/bindings/js/GregorianDateTimeFormatter.mjs +++ b/ffi/capi/bindings/js/GregorianDateTimeFormatter.mjs @@ -1,43 +1,79 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" -import { DateLength_js_to_rust, DateLength_rust_to_js } from "./DateLength.mjs" -import { Error_js_to_rust, Error_rust_to_js } from "./Error.mjs" -import { TimeLength_js_to_rust, TimeLength_rust_to_js } from "./TimeLength.mjs" - -const GregorianDateTimeFormatter_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XGregorianDateTimeFormatter_destroy(underlying); -}); +// generated by diplomat-tool +import { DataProvider } from "./DataProvider.mjs" +import { DateLength } from "./DateLength.mjs" +import { Error } from "./Error.mjs" +import { IsoDateTime } from "./IsoDateTime.mjs" +import { Locale } from "./Locale.mjs" +import { TimeLength } from "./TimeLength.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; + +/** An ICU4X TypedDateTimeFormatter object capable of formatting a [`IsoDateTime`] as a string, +*using the Gregorian Calendar. +* +*See the [Rust documentation for `TypedDateTimeFormatter`](https://docs.rs/icu/latest/icu/datetime/struct.TypedDateTimeFormatter.html) for more information. +*/ + +const GregorianDateTimeFormatter_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XGregorianDateTimeFormatter_destroy(ptr); +}); export class GregorianDateTimeFormatter { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - GregorianDateTimeFormatter_box_destroy_registry.register(this, underlying); + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + + constructor(ptr, selfEdge) { + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + GregorianDateTimeFormatter_box_destroy_registry.register(this, this.#ptr); + } + + get ffiValue() { + return this.#ptr; } - } - - static create_with_lengths(arg_provider, arg_locale, arg_date_length, arg_time_length) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XGregorianDateTimeFormatter_create_with_lengths(diplomat_receive_buffer, arg_provider.underlying, arg_locale.underlying, DateLength_js_to_rust[arg_date_length], TimeLength_js_to_rust[arg_time_length]); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new GregorianDateTimeFormatter(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = Error_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - format_iso_datetime(arg_value) { - return diplomatRuntime.withDiplomatWrite(wasm, (write) => { - return wasm.ICU4XGregorianDateTimeFormatter_format_iso_datetime(this.underlying, arg_value.underlying, write); - }); - } -} + + + static createWithLengths(provider, locale, dateLength, timeLength) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XGregorianDateTimeFormatter_create_with_lengths(diplomat_receive_buffer, provider.ffiValue, locale.ffiValue, dateLength.ffiValue, timeLength.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = (() => {for (let i of Error.values) { if(i[1] === diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)) return Error[i[0]]; } return null;})(); + throw new Error('Error: ' + cause.value, { cause }); + } + return new GregorianDateTimeFormatter(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + formatIsoDatetime(value) { + + const write = wasm.diplomat_buffer_write_create(0); + wasm.ICU4XGregorianDateTimeFormatter_format_iso_datetime(this.ffiValue, value.ffiValue, write); + + try { + + return diplomatRuntime.readString8(wasm, wasm.diplomat_buffer_write_get_bytes(write), wasm.diplomat_buffer_write_len(write)); + } finally { + + wasm.diplomat_buffer_write_destroy(write); + + } + } + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/GregorianZonedDateTimeFormatter.d.ts b/ffi/capi/bindings/js/GregorianZonedDateTimeFormatter.d.ts index f83845794f0..d5a19b33ddf 100644 --- a/ffi/capi/bindings/js/GregorianZonedDateTimeFormatter.d.ts +++ b/ffi/capi/bindings/js/GregorianZonedDateTimeFormatter.d.ts @@ -1,48 +1,30 @@ -import { FFIError } from "./diplomat-runtime" -import { CustomTimeZone } from "./CustomTimeZone"; -import { DataProvider } from "./DataProvider"; -import { DateLength } from "./DateLength"; -import { Error } from "./Error"; -import { IsoDateTime } from "./IsoDateTime"; -import { IsoTimeZoneOptions } from "./IsoTimeZoneOptions"; -import { Locale } from "./Locale"; -import { TimeLength } from "./TimeLength"; - -/** - - * An object capable of formatting a date time with time zone to a string. - - * See the {@link https://docs.rs/icu/latest/icu/datetime/struct.TypedZonedDateTimeFormatter.html Rust documentation for `TypedZonedDateTimeFormatter`} for more information. - */ +// generated by diplomat-tool +import type { CustomTimeZone } from "./CustomTimeZone" +import type { DataProvider } from "./DataProvider" +import type { DateLength } from "./DateLength" +import type { IsoDateTime } from "./IsoDateTime" +import type { IsoTimeZoneOptions } from "./IsoTimeZoneOptions" +import type { Locale } from "./Locale" +import type { TimeLength } from "./TimeLength" +import type { pointer, char } from "./diplomat-runtime.d.ts"; + + +/** An object capable of formatting a date time with time zone to a string. +* +*See the [Rust documentation for `TypedZonedDateTimeFormatter`](https://docs.rs/icu/latest/icu/datetime/struct.TypedZonedDateTimeFormatter.html) for more information. +*/ export class GregorianZonedDateTimeFormatter { + - /** + get ffiValue(): pointer; - * Creates a new {@link GregorianZonedDateTimeFormatter `GregorianZonedDateTimeFormatter`} from locale data. - * This function has `date_length` and `time_length` arguments and uses default options for the time zone. + static createWithLengths(provider: DataProvider, locale: Locale, dateLength: DateLength, timeLength: TimeLength): GregorianZonedDateTimeFormatter; - * See the {@link https://docs.rs/icu/latest/icu/datetime/struct.TypedZonedDateTimeFormatter.html#method.try_new Rust documentation for `try_new`} for more information. - * @throws {@link FFIError}<{@link Error}> - */ - static create_with_lengths(provider: DataProvider, locale: Locale, date_length: DateLength, time_length: TimeLength): GregorianZonedDateTimeFormatter | never; + static createWithLengthsAndIso8601TimeZoneFallback(provider: DataProvider, locale: Locale, dateLength: DateLength, timeLength: TimeLength, zoneOptions: IsoTimeZoneOptions): GregorianZonedDateTimeFormatter; - /** + formatIsoDatetimeWithCustomTimeZone(datetime: IsoDateTime, timeZone: CustomTimeZone): string; - * Creates a new {@link GregorianZonedDateTimeFormatter `GregorianZonedDateTimeFormatter`} from locale data. + - * This function has `date_length` and `time_length` arguments and uses an ISO-8601 style fallback for the time zone with the given configurations. - - * See the {@link https://docs.rs/icu/latest/icu/datetime/struct.TypedZonedDateTimeFormatter.html#method.try_new Rust documentation for `try_new`} for more information. - * @throws {@link FFIError}<{@link Error}> - */ - static create_with_lengths_and_iso_8601_time_zone_fallback(provider: DataProvider, locale: Locale, date_length: DateLength, time_length: TimeLength, zone_options: IsoTimeZoneOptions): GregorianZonedDateTimeFormatter | never; - - /** - - * Formats a {@link IsoDateTime `IsoDateTime`} and {@link CustomTimeZone `CustomTimeZone`} to a string. - - * See the {@link https://docs.rs/icu/latest/icu/datetime/struct.TypedZonedDateTimeFormatter.html#method.format Rust documentation for `format`} for more information. - */ - format_iso_datetime_with_custom_time_zone(datetime: IsoDateTime, time_zone: CustomTimeZone): string; -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/GregorianZonedDateTimeFormatter.mjs b/ffi/capi/bindings/js/GregorianZonedDateTimeFormatter.mjs index e32b583e747..e699513e1dd 100644 --- a/ffi/capi/bindings/js/GregorianZonedDateTimeFormatter.mjs +++ b/ffi/capi/bindings/js/GregorianZonedDateTimeFormatter.mjs @@ -1,66 +1,105 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" -import { DateLength_js_to_rust, DateLength_rust_to_js } from "./DateLength.mjs" -import { Error_js_to_rust, Error_rust_to_js } from "./Error.mjs" -import { IsoTimeZoneFormat_js_to_rust, IsoTimeZoneFormat_rust_to_js } from "./IsoTimeZoneFormat.mjs" -import { IsoTimeZoneMinuteDisplay_js_to_rust, IsoTimeZoneMinuteDisplay_rust_to_js } from "./IsoTimeZoneMinuteDisplay.mjs" -import { IsoTimeZoneSecondDisplay_js_to_rust, IsoTimeZoneSecondDisplay_rust_to_js } from "./IsoTimeZoneSecondDisplay.mjs" -import { TimeLength_js_to_rust, TimeLength_rust_to_js } from "./TimeLength.mjs" +// generated by diplomat-tool +import { CustomTimeZone } from "./CustomTimeZone.mjs" +import { DataProvider } from "./DataProvider.mjs" +import { DateLength } from "./DateLength.mjs" +import { Error } from "./Error.mjs" +import { IsoDateTime } from "./IsoDateTime.mjs" +import { IsoTimeZoneOptions } from "./IsoTimeZoneOptions.mjs" +import { Locale } from "./Locale.mjs" +import { TimeLength } from "./TimeLength.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -const GregorianZonedDateTimeFormatter_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XGregorianZonedDateTimeFormatter_destroy(underlying); -}); +/** An object capable of formatting a date time with time zone to a string. +* +*See the [Rust documentation for `TypedZonedDateTimeFormatter`](https://docs.rs/icu/latest/icu/datetime/struct.TypedZonedDateTimeFormatter.html) for more information. +*/ + +const GregorianZonedDateTimeFormatter_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XGregorianZonedDateTimeFormatter_destroy(ptr); +}); export class GregorianZonedDateTimeFormatter { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - GregorianZonedDateTimeFormatter_box_destroy_registry.register(this, underlying); + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + + constructor(ptr, selfEdge) { + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + GregorianZonedDateTimeFormatter_box_destroy_registry.register(this, this.#ptr); + } + + get ffiValue() { + return this.#ptr; } - } - static create_with_lengths(arg_provider, arg_locale, arg_date_length, arg_time_length) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XGregorianZonedDateTimeFormatter_create_with_lengths(diplomat_receive_buffer, arg_provider.underlying, arg_locale.underlying, DateLength_js_to_rust[arg_date_length], TimeLength_js_to_rust[arg_time_length]); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new GregorianZonedDateTimeFormatter(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = Error_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - static create_with_lengths_and_iso_8601_time_zone_fallback(arg_provider, arg_locale, arg_date_length, arg_time_length, arg_zone_options) { - const field_format_arg_zone_options = arg_zone_options["format"]; - const field_minutes_arg_zone_options = arg_zone_options["minutes"]; - const field_seconds_arg_zone_options = arg_zone_options["seconds"]; - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XGregorianZonedDateTimeFormatter_create_with_lengths_and_iso_8601_time_zone_fallback(diplomat_receive_buffer, arg_provider.underlying, arg_locale.underlying, DateLength_js_to_rust[arg_date_length], TimeLength_js_to_rust[arg_time_length], IsoTimeZoneFormat_js_to_rust[field_format_arg_zone_options], IsoTimeZoneMinuteDisplay_js_to_rust[field_minutes_arg_zone_options], IsoTimeZoneSecondDisplay_js_to_rust[field_seconds_arg_zone_options]); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new GregorianZonedDateTimeFormatter(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = Error_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } + static createWithLengths(provider, locale, dateLength, timeLength) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XGregorianZonedDateTimeFormatter_create_with_lengths(diplomat_receive_buffer, provider.ffiValue, locale.ffiValue, dateLength.ffiValue, timeLength.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = (() => {for (let i of Error.values) { if(i[1] === diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)) return Error[i[0]]; } return null;})(); + throw new Error('Error: ' + cause.value, { cause }); + } + return new GregorianZonedDateTimeFormatter(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static createWithLengthsAndIso8601TimeZoneFallback(provider, locale, dateLength, timeLength, zoneOptions) { + + let slice_cleanup_callbacks = []; + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XGregorianZonedDateTimeFormatter_create_with_lengths_and_iso_8601_time_zone_fallback(diplomat_receive_buffer, provider.ffiValue, locale.ffiValue, dateLength.ffiValue, timeLength.ffiValue, ...zoneOptions._intoFFI(slice_cleanup_callbacks, {})); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = (() => {for (let i of Error.values) { if(i[1] === diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)) return Error[i[0]]; } return null;})(); + throw new Error('Error: ' + cause.value, { cause }); + } + return new GregorianZonedDateTimeFormatter(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + for (let cleanup of slice_cleanup_callbacks) { + cleanup(); + } + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + formatIsoDatetimeWithCustomTimeZone(datetime, timeZone) { + + const write = wasm.diplomat_buffer_write_create(0); + wasm.ICU4XGregorianZonedDateTimeFormatter_format_iso_datetime_with_custom_time_zone(this.ffiValue, datetime.ffiValue, timeZone.ffiValue, write); + + try { + + return diplomatRuntime.readString8(wasm, wasm.diplomat_buffer_write_get_bytes(write), wasm.diplomat_buffer_write_len(write)); + } finally { + + wasm.diplomat_buffer_write_destroy(write); + + } + } + + - format_iso_datetime_with_custom_time_zone(arg_datetime, arg_time_zone) { - return diplomatRuntime.withDiplomatWrite(wasm, (write) => { - return wasm.ICU4XGregorianZonedDateTimeFormatter_format_iso_datetime_with_custom_time_zone(this.underlying, arg_datetime.underlying, arg_time_zone.underlying, write); - }); - } -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/IsoDate.d.ts b/ffi/capi/bindings/js/IsoDate.d.ts index e0dcd3d74e5..3c19d993f8e 100644 --- a/ffi/capi/bindings/js/IsoDate.d.ts +++ b/ffi/capi/bindings/js/IsoDate.d.ts @@ -1,138 +1,52 @@ -import { u8, u16, i32, u32 } from "./diplomat-runtime" -import { FFIError } from "./diplomat-runtime" -import { Calendar } from "./Calendar"; -import { CalendarError } from "./CalendarError"; -import { Date } from "./Date"; -import { IsoWeekday } from "./IsoWeekday"; -import { WeekCalculator } from "./WeekCalculator"; -import { WeekOf } from "./WeekOf"; - -/** - - * An ICU4X Date object capable of containing a ISO-8601 date - - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.Date.html Rust documentation for `Date`} for more information. - */ +// generated by diplomat-tool +import type { Calendar } from "./Calendar" +import type { Date } from "./Date" +import type { IsoWeekday } from "./IsoWeekday" +import type { WeekCalculator } from "./WeekCalculator" +import type { WeekOf } from "./WeekOf" +import type { pointer, char } from "./diplomat-runtime.d.ts"; + + +/** An ICU4X Date object capable of containing a ISO-8601 date +* +*See the [Rust documentation for `Date`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html) for more information. +*/ export class IsoDate { + - /** - - * Creates a new {@link IsoDate `IsoDate`} from the specified date and time. - - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.try_new_iso_date Rust documentation for `try_new_iso_date`} for more information. - * @throws {@link FFIError}<{@link CalendarError}> - */ - static create(year: i32, month: u8, day: u8): IsoDate | never; - - /** - - * Creates a new {@link IsoDate `IsoDate`} representing January 1, 1970. - - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.unix_epoch Rust documentation for `unix_epoch`} for more information. - */ - static create_for_unix_epoch(): IsoDate; - - /** - - * Convert this date to one in a different calendar - - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.to_calendar Rust documentation for `to_calendar`} for more information. - */ - to_calendar(calendar: Calendar): Date; - - /** - - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.to_any Rust documentation for `to_any`} for more information. - */ - to_any(): Date; - - /** - - * Returns the 1-indexed day in the year for this date - - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.day_of_year_info Rust documentation for `day_of_year_info`} for more information. - */ - day_of_year(): u16; - - /** - - * Returns the 1-indexed day in the month for this date - - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.day_of_month Rust documentation for `day_of_month`} for more information. - */ - day_of_month(): u32; - - /** - - * Returns the day in the week for this day - - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.day_of_week Rust documentation for `day_of_week`} for more information. - */ - day_of_week(): IsoWeekday; - - /** - - * Returns the week number in this month, 1-indexed, based on what is considered the first day of the week (often a locale preference). - - * `first_weekday` can be obtained via `first_weekday()` on {@link WeekCalculator `WeekCalculator`} - - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.week_of_month Rust documentation for `week_of_month`} for more information. - */ - week_of_month(first_weekday: IsoWeekday): u32; - - /** - - * Returns the week number in this year, using week data - - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.week_of_year Rust documentation for `week_of_year`} for more information. - */ - week_of_year(calculator: WeekCalculator): WeekOf; + get ffiValue(): pointer; - /** - * Returns 1-indexed number of the month of this date in its year + static create(year: number, month: number, day: number): IsoDate; - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.month Rust documentation for `month`} for more information. - */ - month(): u32; + static createForUnixEpoch(): IsoDate; - /** + toCalendar(calendar: Calendar): Date; - * Returns the year number for this date + toAny(): Date; - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.year Rust documentation for `year`} for more information. - */ - year(): i32; + get dayOfYear(): number; - /** + get dayOfMonth(): number; - * Returns if the year is a leap year for this date + get dayOfWeek(): IsoWeekday; - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.is_in_leap_year Rust documentation for `is_in_leap_year`} for more information. - */ - is_in_leap_year(): boolean; + weekOfMonth(firstWeekday: IsoWeekday): number; - /** + weekOfYear(calculator: WeekCalculator): WeekOf; - * Returns the number of months in the year represented by this date + get month(): number; - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.months_in_year Rust documentation for `months_in_year`} for more information. - */ - months_in_year(): u8; + get year(): number; - /** + get isInLeapYear(): boolean; - * Returns the number of days in the month represented by this date + get monthsInYear(): number; - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.days_in_month Rust documentation for `days_in_month`} for more information. - */ - days_in_month(): u8; + get daysInMonth(): number; - /** + get daysInYear(): number; - * Returns the number of days in the year represented by this date + - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.days_in_year Rust documentation for `days_in_year`} for more information. - */ - days_in_year(): u16; -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/IsoDate.mjs b/ffi/capi/bindings/js/IsoDate.mjs index 821a0f2d073..990848009da 100644 --- a/ffi/capi/bindings/js/IsoDate.mjs +++ b/ffi/capi/bindings/js/IsoDate.mjs @@ -1,101 +1,221 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" -import { CalendarError_js_to_rust, CalendarError_rust_to_js } from "./CalendarError.mjs" +// generated by diplomat-tool +import { Calendar } from "./Calendar.mjs" +import { CalendarError } from "./CalendarError.mjs" import { Date } from "./Date.mjs" -import { IsoWeekday_js_to_rust, IsoWeekday_rust_to_js } from "./IsoWeekday.mjs" +import { IsoWeekday } from "./IsoWeekday.mjs" +import { WeekCalculator } from "./WeekCalculator.mjs" import { WeekOf } from "./WeekOf.mjs" -import { WeekRelativeUnit_js_to_rust, WeekRelativeUnit_rust_to_js } from "./WeekRelativeUnit.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -const IsoDate_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XIsoDate_destroy(underlying); -}); +/** An ICU4X Date object capable of containing a ISO-8601 date +* +*See the [Rust documentation for `Date`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html) for more information. +*/ + +const IsoDate_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XIsoDate_destroy(ptr); +}); export class IsoDate { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - IsoDate_box_destroy_registry.register(this, underlying); - } - } - - static create(arg_year, arg_month, arg_day) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XIsoDate_create(diplomat_receive_buffer, arg_year, arg_month, arg_day); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new IsoDate(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = CalendarError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static create_for_unix_epoch() { - return new IsoDate(wasm.ICU4XIsoDate_create_for_unix_epoch(), true, []); - } - - to_calendar(arg_calendar) { - return new Date(wasm.ICU4XIsoDate_to_calendar(this.underlying, arg_calendar.underlying), true, []); - } - - to_any() { - return new Date(wasm.ICU4XIsoDate_to_any(this.underlying), true, []); - } - - day_of_year() { - return wasm.ICU4XIsoDate_day_of_year(this.underlying); - } - - day_of_month() { - return wasm.ICU4XIsoDate_day_of_month(this.underlying); - } - - day_of_week() { - return IsoWeekday_rust_to_js[wasm.ICU4XIsoDate_day_of_week(this.underlying)]; - } - - week_of_month(arg_first_weekday) { - return wasm.ICU4XIsoDate_week_of_month(this.underlying, IsoWeekday_js_to_rust[arg_first_weekday]); - } - - week_of_year(arg_calculator) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(8, 4); - wasm.ICU4XIsoDate_week_of_year(diplomat_receive_buffer, this.underlying, arg_calculator.underlying); - const out = new WeekOf(diplomat_receive_buffer); - wasm.diplomat_free(diplomat_receive_buffer, 8, 4); - return out; - })(); - } - - month() { - return wasm.ICU4XIsoDate_month(this.underlying); - } - - year() { - return wasm.ICU4XIsoDate_year(this.underlying); - } - - is_in_leap_year() { - return wasm.ICU4XIsoDate_is_in_leap_year(this.underlying); - } - - months_in_year() { - return wasm.ICU4XIsoDate_months_in_year(this.underlying); - } - - days_in_month() { - return wasm.ICU4XIsoDate_days_in_month(this.underlying); - } - - days_in_year() { - return wasm.ICU4XIsoDate_days_in_year(this.underlying); - } -} + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + + constructor(ptr, selfEdge) { + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + IsoDate_box_destroy_registry.register(this, this.#ptr); + } + + get ffiValue() { + return this.#ptr; + } + + + static create(year, month, day) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XIsoDate_create(diplomat_receive_buffer, year, month, day); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = CalendarError[Array.from(CalendarError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('CalendarError: ' + cause.value, { cause }); + } + return new IsoDate(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static createForUnixEpoch() { + const result = wasm.ICU4XIsoDate_create_for_unix_epoch(); + + try { + + return new IsoDate(result, []); + } finally { + + } + } + + toCalendar(calendar) { + const result = wasm.ICU4XIsoDate_to_calendar(this.ffiValue, calendar.ffiValue); + + try { + + return new Date(result, []); + } finally { + + } + } + + toAny() { + const result = wasm.ICU4XIsoDate_to_any(this.ffiValue); + + try { + + return new Date(result, []); + } finally { + + } + } + + get dayOfYear() { + const result = wasm.ICU4XIsoDate_day_of_year(this.ffiValue); + + try { + + return result; + } finally { + + } + } + + get dayOfMonth() { + const result = wasm.ICU4XIsoDate_day_of_month(this.ffiValue); + + try { + + return result; + } finally { + + } + } + + get dayOfWeek() { + const result = wasm.ICU4XIsoDate_day_of_week(this.ffiValue); + + try { + + return (() => {for (let i of IsoWeekday.values) { if(i[1] === result) return IsoWeekday[i[0]]; } return null;})(); + } finally { + + } + } + + weekOfMonth(firstWeekday) { + const result = wasm.ICU4XIsoDate_week_of_month(this.ffiValue, firstWeekday.ffiValue); + + try { + + return result; + } finally { + + } + } + + weekOfYear(calculator) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(8, 4); + const result = wasm.ICU4XIsoDate_week_of_year(diplomat_receive_buffer, this.ffiValue, calculator.ffiValue); + + try { + + return new WeekOf(diplomat_receive_buffer); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 8, 4); + + } + } + + get month() { + const result = wasm.ICU4XIsoDate_month(this.ffiValue); + + try { + + return result; + } finally { + + } + } + + get year() { + const result = wasm.ICU4XIsoDate_year(this.ffiValue); + + try { + + return result; + } finally { + + } + } + + get isInLeapYear() { + const result = wasm.ICU4XIsoDate_is_in_leap_year(this.ffiValue); + + try { + + return result; + } finally { + + } + } + + get monthsInYear() { + const result = wasm.ICU4XIsoDate_months_in_year(this.ffiValue); + + try { + + return result; + } finally { + + } + } + + get daysInMonth() { + const result = wasm.ICU4XIsoDate_days_in_month(this.ffiValue); + + try { + + return result; + } finally { + + } + } + + get daysInYear() { + const result = wasm.ICU4XIsoDate_days_in_year(this.ffiValue); + + try { + + return result; + } finally { + + } + } + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/IsoDateTime.d.ts b/ffi/capi/bindings/js/IsoDateTime.d.ts index ef3bc3ac45e..e7c811affb1 100644 --- a/ffi/capi/bindings/js/IsoDateTime.d.ts +++ b/ffi/capi/bindings/js/IsoDateTime.d.ts @@ -1,214 +1,72 @@ -import { u8, u16, i32, u32 } from "./diplomat-runtime" -import { FFIError } from "./diplomat-runtime" -import { Calendar } from "./Calendar"; -import { CalendarError } from "./CalendarError"; -import { DateTime } from "./DateTime"; -import { IsoDate } from "./IsoDate"; -import { IsoWeekday } from "./IsoWeekday"; -import { Time } from "./Time"; -import { WeekCalculator } from "./WeekCalculator"; -import { WeekOf } from "./WeekOf"; - -/** - - * An ICU4X DateTime object capable of containing a ISO-8601 date and time. - - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.DateTime.html Rust documentation for `DateTime`} for more information. - */ +// generated by diplomat-tool +import type { Calendar } from "./Calendar" +import type { DateTime } from "./DateTime" +import type { IsoDate } from "./IsoDate" +import type { IsoWeekday } from "./IsoWeekday" +import type { Time } from "./Time" +import type { WeekCalculator } from "./WeekCalculator" +import type { WeekOf } from "./WeekOf" +import type { pointer, char } from "./diplomat-runtime.d.ts"; + + +/** An ICU4X DateTime object capable of containing a ISO-8601 date and time. +* +*See the [Rust documentation for `DateTime`](https://docs.rs/icu/latest/icu/calendar/struct.DateTime.html) for more information. +*/ export class IsoDateTime { + - /** + get ffiValue(): pointer; - * Creates a new {@link IsoDateTime `IsoDateTime`} from the specified date and time. - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.DateTime.html#method.try_new_iso_datetime Rust documentation for `try_new_iso_datetime`} for more information. - * @throws {@link FFIError}<{@link CalendarError}> - */ - static create(year: i32, month: u8, day: u8, hour: u8, minute: u8, second: u8, nanosecond: u32): IsoDateTime | never; + static create(year: number, month: number, day: number, hour: number, minute: number, second: number, nanosecond: number): IsoDateTime; - /** + static crateFromDateAndTime(date: IsoDate, time: Time): IsoDateTime; - * Creates a new {@link IsoDateTime `IsoDateTime`} from an {@link IsoDate `IsoDate`} and {@link Time `Time`} object + static localUnixEpoch(): IsoDateTime; - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.DateTime.html#method.new Rust documentation for `new`} for more information. - */ - static crate_from_date_and_time(date: IsoDate, time: Time): IsoDateTime; + static createFromMinutesSinceLocalUnixEpoch(minutes: number): IsoDateTime; - /** + get date(): IsoDate; - * Creates a new {@link IsoDateTime `IsoDateTime`} of midnight on January 1, 1970 + get time(): Time; - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.DateTime.html#method.local_unix_epoch Rust documentation for `local_unix_epoch`} for more information. - */ - static local_unix_epoch(): IsoDateTime; + toAny(): DateTime; - /** + get minutesSinceLocalUnixEpoch(): number; - * Construct from the minutes since the local unix epoch for this date (Jan 1 1970, 00:00) + toCalendar(calendar: Calendar): DateTime; - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.DateTime.html#method.from_minutes_since_local_unix_epoch Rust documentation for `from_minutes_since_local_unix_epoch`} for more information. - */ - static create_from_minutes_since_local_unix_epoch(minutes: i32): IsoDateTime; + get hour(): number; - /** + get minute(): number; - * Gets the date contained in this object + get second(): number; - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.DateTime.html#structfield.date Rust documentation for `date`} for more information. - */ - date(): IsoDate; + get nanosecond(): number; - /** + get dayOfYear(): number; - * Gets the time contained in this object + get dayOfMonth(): number; - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.DateTime.html#structfield.time Rust documentation for `time`} for more information. - */ - time(): Time; + get dayOfWeek(): IsoWeekday; - /** + weekOfMonth(firstWeekday: IsoWeekday): number; - * Converts this to an {@link DateTime `DateTime`} capable of being mixed with dates of other calendars + weekOfYear(calculator: WeekCalculator): WeekOf; - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.DateTime.html#method.to_any Rust documentation for `to_any`} for more information. - */ - to_any(): DateTime; + get month(): number; - /** + get year(): number; - * Gets the minutes since the local unix epoch for this date (Jan 1 1970, 00:00) + get isInLeapYear(): boolean; - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.DateTime.html#method.minutes_since_local_unix_epoch Rust documentation for `minutes_since_local_unix_epoch`} for more information. - */ - minutes_since_local_unix_epoch(): i32; + get monthsInYear(): number; - /** + get daysInMonth(): number; - * Convert this datetime to one in a different calendar + get daysInYear(): number; - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.DateTime.html#method.to_calendar Rust documentation for `to_calendar`} for more information. - */ - to_calendar(calendar: Calendar): DateTime; + - /** - - * Returns the hour in this time - - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.Time.html#structfield.hour Rust documentation for `hour`} for more information. - */ - hour(): u8; - - /** - - * Returns the minute in this time - - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.Time.html#structfield.minute Rust documentation for `minute`} for more information. - */ - minute(): u8; - - /** - - * Returns the second in this time - - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.Time.html#structfield.second Rust documentation for `second`} for more information. - */ - second(): u8; - - /** - - * Returns the nanosecond in this time - - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.Time.html#structfield.nanosecond Rust documentation for `nanosecond`} for more information. - */ - nanosecond(): u32; - - /** - - * Returns the 1-indexed day in the year for this date - - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.day_of_year_info Rust documentation for `day_of_year_info`} for more information. - */ - day_of_year(): u16; - - /** - - * Returns the 1-indexed day in the month for this date - - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.day_of_month Rust documentation for `day_of_month`} for more information. - */ - day_of_month(): u32; - - /** - - * Returns the day in the week for this day - - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.day_of_week Rust documentation for `day_of_week`} for more information. - */ - day_of_week(): IsoWeekday; - - /** - - * Returns the week number in this month, 1-indexed, based on what is considered the first day of the week (often a locale preference). - - * `first_weekday` can be obtained via `first_weekday()` on {@link WeekCalculator `WeekCalculator`} - - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.week_of_month Rust documentation for `week_of_month`} for more information. - */ - week_of_month(first_weekday: IsoWeekday): u32; - - /** - - * Returns the week number in this year, using week data - - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.week_of_year Rust documentation for `week_of_year`} for more information. - */ - week_of_year(calculator: WeekCalculator): WeekOf; - - /** - - * Returns 1-indexed number of the month of this date in its year - - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.month Rust documentation for `month`} for more information. - */ - month(): u32; - - /** - - * Returns the year number for this date - - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.year Rust documentation for `year`} for more information. - */ - year(): i32; - - /** - - * Returns whether this date is in a leap year - - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.is_in_leap_year Rust documentation for `is_in_leap_year`} for more information. - */ - is_in_leap_year(): boolean; - - /** - - * Returns the number of months in the year represented by this date - - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.months_in_year Rust documentation for `months_in_year`} for more information. - */ - months_in_year(): u8; - - /** - - * Returns the number of days in the month represented by this date - - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.days_in_month Rust documentation for `days_in_month`} for more information. - */ - days_in_month(): u8; - - /** - - * Returns the number of days in the year represented by this date - - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.days_in_year Rust documentation for `days_in_year`} for more information. - */ - days_in_year(): u16; -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/IsoDateTime.mjs b/ffi/capi/bindings/js/IsoDateTime.mjs index 01cc75e5307..97fc6f62367 100644 --- a/ffi/capi/bindings/js/IsoDateTime.mjs +++ b/ffi/capi/bindings/js/IsoDateTime.mjs @@ -1,139 +1,322 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" -import { CalendarError_js_to_rust, CalendarError_rust_to_js } from "./CalendarError.mjs" +// generated by diplomat-tool +import { Calendar } from "./Calendar.mjs" +import { CalendarError } from "./CalendarError.mjs" import { DateTime } from "./DateTime.mjs" import { IsoDate } from "./IsoDate.mjs" -import { IsoWeekday_js_to_rust, IsoWeekday_rust_to_js } from "./IsoWeekday.mjs" +import { IsoWeekday } from "./IsoWeekday.mjs" import { Time } from "./Time.mjs" +import { WeekCalculator } from "./WeekCalculator.mjs" import { WeekOf } from "./WeekOf.mjs" -import { WeekRelativeUnit_js_to_rust, WeekRelativeUnit_rust_to_js } from "./WeekRelativeUnit.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -const IsoDateTime_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XIsoDateTime_destroy(underlying); -}); +/** An ICU4X DateTime object capable of containing a ISO-8601 date and time. +* +*See the [Rust documentation for `DateTime`](https://docs.rs/icu/latest/icu/calendar/struct.DateTime.html) for more information. +*/ + +const IsoDateTime_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XIsoDateTime_destroy(ptr); +}); export class IsoDateTime { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - IsoDateTime_box_destroy_registry.register(this, underlying); - } - } - - static create(arg_year, arg_month, arg_day, arg_hour, arg_minute, arg_second, arg_nanosecond) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XIsoDateTime_create(diplomat_receive_buffer, arg_year, arg_month, arg_day, arg_hour, arg_minute, arg_second, arg_nanosecond); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new IsoDateTime(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = CalendarError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static crate_from_date_and_time(arg_date, arg_time) { - return new IsoDateTime(wasm.ICU4XIsoDateTime_crate_from_date_and_time(arg_date.underlying, arg_time.underlying), true, []); - } - - static local_unix_epoch() { - return new IsoDateTime(wasm.ICU4XIsoDateTime_local_unix_epoch(), true, []); - } - - static create_from_minutes_since_local_unix_epoch(arg_minutes) { - return new IsoDateTime(wasm.ICU4XIsoDateTime_create_from_minutes_since_local_unix_epoch(arg_minutes), true, []); - } - - date() { - return new IsoDate(wasm.ICU4XIsoDateTime_date(this.underlying), true, []); - } - - time() { - return new Time(wasm.ICU4XIsoDateTime_time(this.underlying), true, []); - } - - to_any() { - return new DateTime(wasm.ICU4XIsoDateTime_to_any(this.underlying), true, []); - } - - minutes_since_local_unix_epoch() { - return wasm.ICU4XIsoDateTime_minutes_since_local_unix_epoch(this.underlying); - } - - to_calendar(arg_calendar) { - return new DateTime(wasm.ICU4XIsoDateTime_to_calendar(this.underlying, arg_calendar.underlying), true, []); - } - - hour() { - return wasm.ICU4XIsoDateTime_hour(this.underlying); - } - - minute() { - return wasm.ICU4XIsoDateTime_minute(this.underlying); - } - - second() { - return wasm.ICU4XIsoDateTime_second(this.underlying); - } - - nanosecond() { - return wasm.ICU4XIsoDateTime_nanosecond(this.underlying); - } - - day_of_year() { - return wasm.ICU4XIsoDateTime_day_of_year(this.underlying); - } - - day_of_month() { - return wasm.ICU4XIsoDateTime_day_of_month(this.underlying); - } - - day_of_week() { - return IsoWeekday_rust_to_js[wasm.ICU4XIsoDateTime_day_of_week(this.underlying)]; - } - - week_of_month(arg_first_weekday) { - return wasm.ICU4XIsoDateTime_week_of_month(this.underlying, IsoWeekday_js_to_rust[arg_first_weekday]); - } - - week_of_year(arg_calculator) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(8, 4); - wasm.ICU4XIsoDateTime_week_of_year(diplomat_receive_buffer, this.underlying, arg_calculator.underlying); - const out = new WeekOf(diplomat_receive_buffer); - wasm.diplomat_free(diplomat_receive_buffer, 8, 4); - return out; - })(); - } - - month() { - return wasm.ICU4XIsoDateTime_month(this.underlying); - } - - year() { - return wasm.ICU4XIsoDateTime_year(this.underlying); - } - - is_in_leap_year() { - return wasm.ICU4XIsoDateTime_is_in_leap_year(this.underlying); - } - - months_in_year() { - return wasm.ICU4XIsoDateTime_months_in_year(this.underlying); - } - - days_in_month() { - return wasm.ICU4XIsoDateTime_days_in_month(this.underlying); - } - - days_in_year() { - return wasm.ICU4XIsoDateTime_days_in_year(this.underlying); - } -} + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + + constructor(ptr, selfEdge) { + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + IsoDateTime_box_destroy_registry.register(this, this.#ptr); + } + + get ffiValue() { + return this.#ptr; + } + + + static create(year, month, day, hour, minute, second, nanosecond) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XIsoDateTime_create(diplomat_receive_buffer, year, month, day, hour, minute, second, nanosecond); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = CalendarError[Array.from(CalendarError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('CalendarError: ' + cause.value, { cause }); + } + return new IsoDateTime(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static crateFromDateAndTime(date, time) { + const result = wasm.ICU4XIsoDateTime_crate_from_date_and_time(date.ffiValue, time.ffiValue); + + try { + + return new IsoDateTime(result, []); + } finally { + + } + } + + static localUnixEpoch() { + const result = wasm.ICU4XIsoDateTime_local_unix_epoch(); + + try { + + return new IsoDateTime(result, []); + } finally { + + } + } + + static createFromMinutesSinceLocalUnixEpoch(minutes) { + const result = wasm.ICU4XIsoDateTime_create_from_minutes_since_local_unix_epoch(minutes); + + try { + + return new IsoDateTime(result, []); + } finally { + + } + } + + get date() { + const result = wasm.ICU4XIsoDateTime_date(this.ffiValue); + + try { + + return new IsoDate(result, []); + } finally { + + } + } + + get time() { + const result = wasm.ICU4XIsoDateTime_time(this.ffiValue); + + try { + + return new Time(result, []); + } finally { + + } + } + + toAny() { + const result = wasm.ICU4XIsoDateTime_to_any(this.ffiValue); + + try { + + return new DateTime(result, []); + } finally { + + } + } + + get minutesSinceLocalUnixEpoch() { + const result = wasm.ICU4XIsoDateTime_minutes_since_local_unix_epoch(this.ffiValue); + + try { + + return result; + } finally { + + } + } + + toCalendar(calendar) { + const result = wasm.ICU4XIsoDateTime_to_calendar(this.ffiValue, calendar.ffiValue); + + try { + + return new DateTime(result, []); + } finally { + + } + } + + get hour() { + const result = wasm.ICU4XIsoDateTime_hour(this.ffiValue); + + try { + + return result; + } finally { + + } + } + + get minute() { + const result = wasm.ICU4XIsoDateTime_minute(this.ffiValue); + + try { + + return result; + } finally { + + } + } + + get second() { + const result = wasm.ICU4XIsoDateTime_second(this.ffiValue); + + try { + + return result; + } finally { + + } + } + + get nanosecond() { + const result = wasm.ICU4XIsoDateTime_nanosecond(this.ffiValue); + + try { + + return result; + } finally { + + } + } + + get dayOfYear() { + const result = wasm.ICU4XIsoDateTime_day_of_year(this.ffiValue); + + try { + + return result; + } finally { + + } + } + + get dayOfMonth() { + const result = wasm.ICU4XIsoDateTime_day_of_month(this.ffiValue); + + try { + + return result; + } finally { + + } + } + + get dayOfWeek() { + const result = wasm.ICU4XIsoDateTime_day_of_week(this.ffiValue); + + try { + + return (() => {for (let i of IsoWeekday.values) { if(i[1] === result) return IsoWeekday[i[0]]; } return null;})(); + } finally { + + } + } + + weekOfMonth(firstWeekday) { + const result = wasm.ICU4XIsoDateTime_week_of_month(this.ffiValue, firstWeekday.ffiValue); + + try { + + return result; + } finally { + + } + } + + weekOfYear(calculator) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(8, 4); + const result = wasm.ICU4XIsoDateTime_week_of_year(diplomat_receive_buffer, this.ffiValue, calculator.ffiValue); + + try { + + return new WeekOf(diplomat_receive_buffer); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 8, 4); + + } + } + + get month() { + const result = wasm.ICU4XIsoDateTime_month(this.ffiValue); + + try { + + return result; + } finally { + + } + } + + get year() { + const result = wasm.ICU4XIsoDateTime_year(this.ffiValue); + + try { + + return result; + } finally { + + } + } + + get isInLeapYear() { + const result = wasm.ICU4XIsoDateTime_is_in_leap_year(this.ffiValue); + + try { + + return result; + } finally { + + } + } + + get monthsInYear() { + const result = wasm.ICU4XIsoDateTime_months_in_year(this.ffiValue); + + try { + + return result; + } finally { + + } + } + + get daysInMonth() { + const result = wasm.ICU4XIsoDateTime_days_in_month(this.ffiValue); + + try { + + return result; + } finally { + + } + } + + get daysInYear() { + const result = wasm.ICU4XIsoDateTime_days_in_year(this.ffiValue); + + try { + + return result; + } finally { + + } + } + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/IsoTimeZoneFormat.d.ts b/ffi/capi/bindings/js/IsoTimeZoneFormat.d.ts index 38f8b690e50..3fb125ac12b 100644 --- a/ffi/capi/bindings/js/IsoTimeZoneFormat.d.ts +++ b/ffi/capi/bindings/js/IsoTimeZoneFormat.d.ts @@ -1,19 +1,25 @@ +// generated by diplomat-tool +import type { pointer, char } from "./diplomat-runtime.d.ts"; + +// Base enumerator definition +/** See the [Rust documentation for `IsoFormat`](https://docs.rs/icu/latest/icu/datetime/time_zone/enum.IsoFormat.html) for more information. +*/ +export class IsoTimeZoneFormat { + constructor(value : IsoTimeZoneFormat | string); + + get value() : string; + + get ffiValue() : number; + + static Basic : IsoTimeZoneFormat; + + static Extended : IsoTimeZoneFormat; + + static UtcBasic : IsoTimeZoneFormat; + + static UtcExtended : IsoTimeZoneFormat; + + + -/** - - * See the {@link https://docs.rs/icu/latest/icu/datetime/time_zone/enum.IsoFormat.html Rust documentation for `IsoFormat`} for more information. - */ -export enum IsoTimeZoneFormat { - /** - */ - Basic = 'Basic', - /** - */ - Extended = 'Extended', - /** - */ - UtcBasic = 'UtcBasic', - /** - */ - UtcExtended = 'UtcExtended', } \ No newline at end of file diff --git a/ffi/capi/bindings/js/IsoTimeZoneFormat.mjs b/ffi/capi/bindings/js/IsoTimeZoneFormat.mjs index b6413275222..0f41066a749 100644 --- a/ffi/capi/bindings/js/IsoTimeZoneFormat.mjs +++ b/ffi/capi/bindings/js/IsoTimeZoneFormat.mjs @@ -1,23 +1,50 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" - -export const IsoTimeZoneFormat_js_to_rust = { - "Basic": 0, - "Extended": 1, - "UtcBasic": 2, - "UtcExtended": 3, -}; - -export const IsoTimeZoneFormat_rust_to_js = { - [0]: "Basic", - [1]: "Extended", - [2]: "UtcBasic", - [3]: "UtcExtended", -}; - -export const IsoTimeZoneFormat = { - "Basic": "Basic", - "Extended": "Extended", - "UtcBasic": "UtcBasic", - "UtcExtended": "UtcExtended", -}; +// generated by diplomat-tool +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; + +// Base enumerator definition +/** See the [Rust documentation for `IsoFormat`](https://docs.rs/icu/latest/icu/datetime/time_zone/enum.IsoFormat.html) for more information. +*/ +export class IsoTimeZoneFormat { + #value = undefined; + + static values = new Map([ + ["Basic", 0], + ["Extended", 1], + ["UtcBasic", 2], + ["UtcExtended", 3] + ]); + constructor(value) { + if (value instanceof IsoTimeZoneFormat) { + this.#value = value.value; + return; + } + + if (IsoTimeZoneFormat.values.has(value)) { + this.#value = value; + return; + } + + throw TypeError(value + " is not a IsoTimeZoneFormat and does not correspond to any of its enumerator values."); + } + + get value() { + return this.#value; + } + + get ffiValue() { + return IsoTimeZoneFormat.values.get(this.#value); + } + + static Basic = new IsoTimeZoneFormat("Basic"); + + static Extended = new IsoTimeZoneFormat("Extended"); + + static UtcBasic = new IsoTimeZoneFormat("UtcBasic"); + + static UtcExtended = new IsoTimeZoneFormat("UtcExtended"); + + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/IsoTimeZoneMinuteDisplay.d.ts b/ffi/capi/bindings/js/IsoTimeZoneMinuteDisplay.d.ts index b92417f3621..ea4465209a3 100644 --- a/ffi/capi/bindings/js/IsoTimeZoneMinuteDisplay.d.ts +++ b/ffi/capi/bindings/js/IsoTimeZoneMinuteDisplay.d.ts @@ -1,13 +1,21 @@ +// generated by diplomat-tool +import type { pointer, char } from "./diplomat-runtime.d.ts"; + +// Base enumerator definition +/** See the [Rust documentation for `IsoMinutes`](https://docs.rs/icu/latest/icu/datetime/time_zone/enum.IsoMinutes.html) for more information. +*/ +export class IsoTimeZoneMinuteDisplay { + constructor(value : IsoTimeZoneMinuteDisplay | string); + + get value() : string; + + get ffiValue() : number; + + static Required : IsoTimeZoneMinuteDisplay; + + static Optional : IsoTimeZoneMinuteDisplay; + + + -/** - - * See the {@link https://docs.rs/icu/latest/icu/datetime/time_zone/enum.IsoMinutes.html Rust documentation for `IsoMinutes`} for more information. - */ -export enum IsoTimeZoneMinuteDisplay { - /** - */ - Required = 'Required', - /** - */ - Optional = 'Optional', } \ No newline at end of file diff --git a/ffi/capi/bindings/js/IsoTimeZoneMinuteDisplay.mjs b/ffi/capi/bindings/js/IsoTimeZoneMinuteDisplay.mjs index 172677d6aed..21dbc730162 100644 --- a/ffi/capi/bindings/js/IsoTimeZoneMinuteDisplay.mjs +++ b/ffi/capi/bindings/js/IsoTimeZoneMinuteDisplay.mjs @@ -1,17 +1,44 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" - -export const IsoTimeZoneMinuteDisplay_js_to_rust = { - "Required": 0, - "Optional": 1, -}; - -export const IsoTimeZoneMinuteDisplay_rust_to_js = { - [0]: "Required", - [1]: "Optional", -}; - -export const IsoTimeZoneMinuteDisplay = { - "Required": "Required", - "Optional": "Optional", -}; +// generated by diplomat-tool +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; + +// Base enumerator definition +/** See the [Rust documentation for `IsoMinutes`](https://docs.rs/icu/latest/icu/datetime/time_zone/enum.IsoMinutes.html) for more information. +*/ +export class IsoTimeZoneMinuteDisplay { + #value = undefined; + + static values = new Map([ + ["Required", 0], + ["Optional", 1] + ]); + constructor(value) { + if (value instanceof IsoTimeZoneMinuteDisplay) { + this.#value = value.value; + return; + } + + if (IsoTimeZoneMinuteDisplay.values.has(value)) { + this.#value = value; + return; + } + + throw TypeError(value + " is not a IsoTimeZoneMinuteDisplay and does not correspond to any of its enumerator values."); + } + + get value() { + return this.#value; + } + + get ffiValue() { + return IsoTimeZoneMinuteDisplay.values.get(this.#value); + } + + static Required = new IsoTimeZoneMinuteDisplay("Required"); + + static Optional = new IsoTimeZoneMinuteDisplay("Optional"); + + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/IsoTimeZoneOptions.d.ts b/ffi/capi/bindings/js/IsoTimeZoneOptions.d.ts index 06f8b2893ca..18b97bb5ba8 100644 --- a/ffi/capi/bindings/js/IsoTimeZoneOptions.d.ts +++ b/ffi/capi/bindings/js/IsoTimeZoneOptions.d.ts @@ -1,11 +1,17 @@ -import { IsoTimeZoneFormat } from "./IsoTimeZoneFormat"; -import { IsoTimeZoneMinuteDisplay } from "./IsoTimeZoneMinuteDisplay"; -import { IsoTimeZoneSecondDisplay } from "./IsoTimeZoneSecondDisplay"; +// generated by diplomat-tool +import type { IsoTimeZoneFormat } from "./IsoTimeZoneFormat" +import type { IsoTimeZoneMinuteDisplay } from "./IsoTimeZoneMinuteDisplay" +import type { IsoTimeZoneSecondDisplay } from "./IsoTimeZoneSecondDisplay" +import type { pointer, char } from "./diplomat-runtime.d.ts"; -/** - */ export class IsoTimeZoneOptions { - format: IsoTimeZoneFormat; - minutes: IsoTimeZoneMinuteDisplay; - seconds: IsoTimeZoneSecondDisplay; -} + get format() : IsoTimeZoneFormat; + set format(value: IsoTimeZoneFormat); + get minutes() : IsoTimeZoneMinuteDisplay; + set minutes(value: IsoTimeZoneMinuteDisplay); + get seconds() : IsoTimeZoneSecondDisplay; + set seconds(value: IsoTimeZoneSecondDisplay); + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/IsoTimeZoneOptions.mjs b/ffi/capi/bindings/js/IsoTimeZoneOptions.mjs index bde92928f65..80d1ed10680 100644 --- a/ffi/capi/bindings/js/IsoTimeZoneOptions.mjs +++ b/ffi/capi/bindings/js/IsoTimeZoneOptions.mjs @@ -1,13 +1,58 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" -import { IsoTimeZoneFormat_js_to_rust, IsoTimeZoneFormat_rust_to_js } from "./IsoTimeZoneFormat.mjs" -import { IsoTimeZoneMinuteDisplay_js_to_rust, IsoTimeZoneMinuteDisplay_rust_to_js } from "./IsoTimeZoneMinuteDisplay.mjs" -import { IsoTimeZoneSecondDisplay_js_to_rust, IsoTimeZoneSecondDisplay_rust_to_js } from "./IsoTimeZoneSecondDisplay.mjs" +// generated by diplomat-tool +import { IsoTimeZoneFormat } from "./IsoTimeZoneFormat.mjs" +import { IsoTimeZoneMinuteDisplay } from "./IsoTimeZoneMinuteDisplay.mjs" +import { IsoTimeZoneSecondDisplay } from "./IsoTimeZoneSecondDisplay.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; export class IsoTimeZoneOptions { - constructor(underlying) { - this.format = IsoTimeZoneFormat_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, underlying)]; - this.minutes = IsoTimeZoneMinuteDisplay_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, underlying + 4)]; - this.seconds = IsoTimeZoneSecondDisplay_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, underlying + 8)]; - } -} + #format; + get format() { + return this.#format; + } + set format(value) { + this.#format = value; + } + #minutes; + get minutes() { + return this.#minutes; + } + set minutes(value) { + this.#minutes = value; + } + #seconds; + get seconds() { + return this.#seconds; + } + set seconds(value) { + this.#seconds = value; + } + + // Return this struct in FFI function friendly format. + // Returns an array that can be expanded with spread syntax (...) + + _intoFFI( + slice_cleanup_callbacks, + appendArrayMap + ) { + return [this.#format.ffiValue, this.#minutes.ffiValue, this.#seconds.ffiValue] + } + + // 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. + _fromFFI(ptr) { + const formatDeref = diplomatRuntime.enumDiscriminant(wasm, ptr); + this.#format = IsoTimeZoneFormat[Array.from(IsoTimeZoneFormat.values.keys())[formatDeref]]; + const minutesDeref = diplomatRuntime.enumDiscriminant(wasm, ptr + 4); + this.#minutes = IsoTimeZoneMinuteDisplay[Array.from(IsoTimeZoneMinuteDisplay.values.keys())[minutesDeref]]; + const secondsDeref = diplomatRuntime.enumDiscriminant(wasm, ptr + 8); + this.#seconds = IsoTimeZoneSecondDisplay[Array.from(IsoTimeZoneSecondDisplay.values.keys())[secondsDeref]]; + + return this; + } + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/IsoTimeZoneSecondDisplay.d.ts b/ffi/capi/bindings/js/IsoTimeZoneSecondDisplay.d.ts index 570ea894c46..ea1e2b6a233 100644 --- a/ffi/capi/bindings/js/IsoTimeZoneSecondDisplay.d.ts +++ b/ffi/capi/bindings/js/IsoTimeZoneSecondDisplay.d.ts @@ -1,13 +1,21 @@ +// generated by diplomat-tool +import type { pointer, char } from "./diplomat-runtime.d.ts"; + +// Base enumerator definition +/** See the [Rust documentation for `IsoSeconds`](https://docs.rs/icu/latest/icu/datetime/time_zone/enum.IsoSeconds.html) for more information. +*/ +export class IsoTimeZoneSecondDisplay { + constructor(value : IsoTimeZoneSecondDisplay | string); + + get value() : string; + + get ffiValue() : number; + + static Optional : IsoTimeZoneSecondDisplay; + + static Never : IsoTimeZoneSecondDisplay; + + + -/** - - * See the {@link https://docs.rs/icu/latest/icu/datetime/time_zone/enum.IsoSeconds.html Rust documentation for `IsoSeconds`} for more information. - */ -export enum IsoTimeZoneSecondDisplay { - /** - */ - Optional = 'Optional', - /** - */ - Never = 'Never', } \ No newline at end of file diff --git a/ffi/capi/bindings/js/IsoTimeZoneSecondDisplay.mjs b/ffi/capi/bindings/js/IsoTimeZoneSecondDisplay.mjs index f0001ee1d7b..3399450f067 100644 --- a/ffi/capi/bindings/js/IsoTimeZoneSecondDisplay.mjs +++ b/ffi/capi/bindings/js/IsoTimeZoneSecondDisplay.mjs @@ -1,17 +1,44 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" - -export const IsoTimeZoneSecondDisplay_js_to_rust = { - "Optional": 0, - "Never": 1, -}; - -export const IsoTimeZoneSecondDisplay_rust_to_js = { - [0]: "Optional", - [1]: "Never", -}; - -export const IsoTimeZoneSecondDisplay = { - "Optional": "Optional", - "Never": "Never", -}; +// generated by diplomat-tool +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; + +// Base enumerator definition +/** See the [Rust documentation for `IsoSeconds`](https://docs.rs/icu/latest/icu/datetime/time_zone/enum.IsoSeconds.html) for more information. +*/ +export class IsoTimeZoneSecondDisplay { + #value = undefined; + + static values = new Map([ + ["Optional", 0], + ["Never", 1] + ]); + constructor(value) { + if (value instanceof IsoTimeZoneSecondDisplay) { + this.#value = value.value; + return; + } + + if (IsoTimeZoneSecondDisplay.values.has(value)) { + this.#value = value; + return; + } + + throw TypeError(value + " is not a IsoTimeZoneSecondDisplay and does not correspond to any of its enumerator values."); + } + + get value() { + return this.#value; + } + + get ffiValue() { + return IsoTimeZoneSecondDisplay.values.get(this.#value); + } + + static Optional = new IsoTimeZoneSecondDisplay("Optional"); + + static Never = new IsoTimeZoneSecondDisplay("Never"); + + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/IsoWeekday.d.ts b/ffi/capi/bindings/js/IsoWeekday.d.ts index 3063fa5e85b..68a80ceb948 100644 --- a/ffi/capi/bindings/js/IsoWeekday.d.ts +++ b/ffi/capi/bindings/js/IsoWeekday.d.ts @@ -1,26 +1,29 @@ +// generated by diplomat-tool +import type { pointer, char } from "./diplomat-runtime.d.ts"; + +// Base enumerator definition +export class IsoWeekday { + constructor(value : IsoWeekday | string); + + get value() : string; + + get ffiValue() : number; + + static Monday : IsoWeekday; + + static Tuesday : IsoWeekday; + + static Wednesday : IsoWeekday; + + static Thursday : IsoWeekday; + + static Friday : IsoWeekday; + + static Saturday : IsoWeekday; + + static Sunday : IsoWeekday; + + + -/** - */ -export enum IsoWeekday { - /** - */ - Monday = 'Monday', - /** - */ - Tuesday = 'Tuesday', - /** - */ - Wednesday = 'Wednesday', - /** - */ - Thursday = 'Thursday', - /** - */ - Friday = 'Friday', - /** - */ - Saturday = 'Saturday', - /** - */ - Sunday = 'Sunday', } \ No newline at end of file diff --git a/ffi/capi/bindings/js/IsoWeekday.mjs b/ffi/capi/bindings/js/IsoWeekday.mjs index b986980bdd1..b4e4eeca605 100644 --- a/ffi/capi/bindings/js/IsoWeekday.mjs +++ b/ffi/capi/bindings/js/IsoWeekday.mjs @@ -1,32 +1,57 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" - -export const IsoWeekday_js_to_rust = { - "Monday": 1, - "Tuesday": 2, - "Wednesday": 3, - "Thursday": 4, - "Friday": 5, - "Saturday": 6, - "Sunday": 7, -}; - -export const IsoWeekday_rust_to_js = { - [1]: "Monday", - [2]: "Tuesday", - [3]: "Wednesday", - [4]: "Thursday", - [5]: "Friday", - [6]: "Saturday", - [7]: "Sunday", -}; - -export const IsoWeekday = { - "Monday": "Monday", - "Tuesday": "Tuesday", - "Wednesday": "Wednesday", - "Thursday": "Thursday", - "Friday": "Friday", - "Saturday": "Saturday", - "Sunday": "Sunday", -}; +// generated by diplomat-tool +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; + +// Base enumerator definition +export class IsoWeekday { + #value = undefined; + + static values = new Map([ + ["Monday", 1], + ["Tuesday", 2], + ["Wednesday", 3], + ["Thursday", 4], + ["Friday", 5], + ["Saturday", 6], + ["Sunday", 7] + ]); + constructor(value) { + if (value instanceof IsoWeekday) { + this.#value = value.value; + return; + } + + if (IsoWeekday.values.has(value)) { + this.#value = value; + return; + } + + throw TypeError(value + " is not a IsoWeekday and does not correspond to any of its enumerator values."); + } + + get value() { + return this.#value; + } + + get ffiValue() { + return IsoWeekday.values.get(this.#value); + } + + static Monday = new IsoWeekday("Monday"); + + static Tuesday = new IsoWeekday("Tuesday"); + + static Wednesday = new IsoWeekday("Wednesday"); + + static Thursday = new IsoWeekday("Thursday"); + + static Friday = new IsoWeekday("Friday"); + + static Saturday = new IsoWeekday("Saturday"); + + static Sunday = new IsoWeekday("Sunday"); + + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/LanguageDisplay.d.ts b/ffi/capi/bindings/js/LanguageDisplay.d.ts index e43ca6146cd..5bf65e03bb4 100644 --- a/ffi/capi/bindings/js/LanguageDisplay.d.ts +++ b/ffi/capi/bindings/js/LanguageDisplay.d.ts @@ -1,13 +1,21 @@ +// generated by diplomat-tool +import type { pointer, char } from "./diplomat-runtime.d.ts"; + +// Base enumerator definition +/** See the [Rust documentation for `LanguageDisplay`](https://docs.rs/icu/latest/icu/displaynames/options/enum.LanguageDisplay.html) for more information. +*/ +export class LanguageDisplay { + constructor(value : LanguageDisplay | string); + + get value() : string; + + get ffiValue() : number; + + static Dialect : LanguageDisplay; + + static Standard : LanguageDisplay; + + + -/** - - * See the {@link https://docs.rs/icu/latest/icu/displaynames/options/enum.LanguageDisplay.html Rust documentation for `LanguageDisplay`} for more information. - */ -export enum LanguageDisplay { - /** - */ - Dialect = 'Dialect', - /** - */ - Standard = 'Standard', } \ No newline at end of file diff --git a/ffi/capi/bindings/js/LanguageDisplay.mjs b/ffi/capi/bindings/js/LanguageDisplay.mjs index 30d2e698aed..2bf95ea711c 100644 --- a/ffi/capi/bindings/js/LanguageDisplay.mjs +++ b/ffi/capi/bindings/js/LanguageDisplay.mjs @@ -1,17 +1,44 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" - -export const LanguageDisplay_js_to_rust = { - "Dialect": 0, - "Standard": 1, -}; - -export const LanguageDisplay_rust_to_js = { - [0]: "Dialect", - [1]: "Standard", -}; - -export const LanguageDisplay = { - "Dialect": "Dialect", - "Standard": "Standard", -}; +// generated by diplomat-tool +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; + +// Base enumerator definition +/** See the [Rust documentation for `LanguageDisplay`](https://docs.rs/icu/latest/icu/displaynames/options/enum.LanguageDisplay.html) for more information. +*/ +export class LanguageDisplay { + #value = undefined; + + static values = new Map([ + ["Dialect", 0], + ["Standard", 1] + ]); + constructor(value) { + if (value instanceof LanguageDisplay) { + this.#value = value.value; + return; + } + + if (LanguageDisplay.values.has(value)) { + this.#value = value; + return; + } + + throw TypeError(value + " is not a LanguageDisplay and does not correspond to any of its enumerator values."); + } + + get value() { + return this.#value; + } + + get ffiValue() { + return LanguageDisplay.values.get(this.#value); + } + + static Dialect = new LanguageDisplay("Dialect"); + + static Standard = new LanguageDisplay("Standard"); + + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/LeadingAdjustment.d.ts b/ffi/capi/bindings/js/LeadingAdjustment.d.ts index c9b808c6ce7..0c31b56ea22 100644 --- a/ffi/capi/bindings/js/LeadingAdjustment.d.ts +++ b/ffi/capi/bindings/js/LeadingAdjustment.d.ts @@ -1,16 +1,23 @@ +// generated by diplomat-tool +import type { pointer, char } from "./diplomat-runtime.d.ts"; + +// Base enumerator definition +/** See the [Rust documentation for `LeadingAdjustment`](https://docs.rs/icu/latest/icu/casemap/titlecase/enum.LeadingAdjustment.html) for more information. +*/ +export class LeadingAdjustment { + constructor(value : LeadingAdjustment | string); + + get value() : string; + + get ffiValue() : number; + + static Auto : LeadingAdjustment; + + static None : LeadingAdjustment; + + static ToCased : LeadingAdjustment; + + + -/** - - * See the {@link https://docs.rs/icu/latest/icu/casemap/titlecase/enum.LeadingAdjustment.html Rust documentation for `LeadingAdjustment`} for more information. - */ -export enum LeadingAdjustment { - /** - */ - Auto = 'Auto', - /** - */ - None = 'None', - /** - */ - ToCased = 'ToCased', } \ No newline at end of file diff --git a/ffi/capi/bindings/js/LeadingAdjustment.mjs b/ffi/capi/bindings/js/LeadingAdjustment.mjs index de10f00d33e..604ade4e87b 100644 --- a/ffi/capi/bindings/js/LeadingAdjustment.mjs +++ b/ffi/capi/bindings/js/LeadingAdjustment.mjs @@ -1,20 +1,47 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" - -export const LeadingAdjustment_js_to_rust = { - "Auto": 0, - "None": 1, - "ToCased": 2, -}; - -export const LeadingAdjustment_rust_to_js = { - [0]: "Auto", - [1]: "None", - [2]: "ToCased", -}; - -export const LeadingAdjustment = { - "Auto": "Auto", - "None": "None", - "ToCased": "ToCased", -}; +// generated by diplomat-tool +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; + +// Base enumerator definition +/** See the [Rust documentation for `LeadingAdjustment`](https://docs.rs/icu/latest/icu/casemap/titlecase/enum.LeadingAdjustment.html) for more information. +*/ +export class LeadingAdjustment { + #value = undefined; + + static values = new Map([ + ["Auto", 0], + ["None", 1], + ["ToCased", 2] + ]); + constructor(value) { + if (value instanceof LeadingAdjustment) { + this.#value = value.value; + return; + } + + if (LeadingAdjustment.values.has(value)) { + this.#value = value; + return; + } + + throw TypeError(value + " is not a LeadingAdjustment and does not correspond to any of its enumerator values."); + } + + get value() { + return this.#value; + } + + get ffiValue() { + return LeadingAdjustment.values.get(this.#value); + } + + static Auto = new LeadingAdjustment("Auto"); + + static None = new LeadingAdjustment("None"); + + static ToCased = new LeadingAdjustment("ToCased"); + + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/LineBreakIteratorLatin1.d.ts b/ffi/capi/bindings/js/LineBreakIteratorLatin1.d.ts index 28ae8da8415..d7aee4605fd 100644 --- a/ffi/capi/bindings/js/LineBreakIteratorLatin1.d.ts +++ b/ffi/capi/bindings/js/LineBreakIteratorLatin1.d.ts @@ -1,18 +1,19 @@ -import { i32 } from "./diplomat-runtime" +// generated by diplomat-tool +import type { pointer, char } from "./diplomat-runtime.d.ts"; -/** - * See the {@link https://docs.rs/icu/latest/icu/segmenter/struct.LineBreakIterator.html Rust documentation for `LineBreakIterator`} for more information. - - * Additional information: {@link https://docs.rs/icu/latest/icu/segmenter/type.LineBreakIteratorLatin1.html 1} - */ +/** See the [Rust documentation for `LineBreakIterator`](https://docs.rs/icu/latest/icu/segmenter/struct.LineBreakIterator.html) for more information. +* +*Additional information: [1](https://docs.rs/icu/latest/icu/segmenter/type.LineBreakIteratorLatin1.html) +*/ export class LineBreakIteratorLatin1 { + + + get ffiValue(): pointer; + - /** + next(): number; - * Finds the next breakpoint. Returns -1 if at the end of the string or if the index is out of range of a 32-bit signed integer. + - * See the {@link https://docs.rs/icu/latest/icu/segmenter/struct.LineBreakIterator.html#method.next Rust documentation for `next`} for more information. - */ - next(): i32; -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/LineBreakIteratorLatin1.mjs b/ffi/capi/bindings/js/LineBreakIteratorLatin1.mjs index db824eab413..6053e784f71 100644 --- a/ffi/capi/bindings/js/LineBreakIteratorLatin1.mjs +++ b/ffi/capi/bindings/js/LineBreakIteratorLatin1.mjs @@ -1,21 +1,54 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" +// generated by diplomat-tool +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -const LineBreakIteratorLatin1_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XLineBreakIteratorLatin1_destroy(underlying); -}); +/** See the [Rust documentation for `LineBreakIterator`](https://docs.rs/icu/latest/icu/segmenter/struct.LineBreakIterator.html) for more information. +* +*Additional information: [1](https://docs.rs/icu/latest/icu/segmenter/type.LineBreakIteratorLatin1.html) +*/ + +const LineBreakIteratorLatin1_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XLineBreakIteratorLatin1_destroy(ptr); +}); export class LineBreakIteratorLatin1 { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - LineBreakIteratorLatin1_box_destroy_registry.register(this, underlying); + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + #aEdge = []; + + + constructor(ptr, selfEdge, aEdge) { + + + this.#aEdge = aEdge; + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + LineBreakIteratorLatin1_box_destroy_registry.register(this, this.#ptr); + } + + get ffiValue() { + return this.#ptr; } - } - next() { - return wasm.ICU4XLineBreakIteratorLatin1_next(this.underlying); - } -} + + next() { + const result = wasm.ICU4XLineBreakIteratorLatin1_next(this.ffiValue); + + try { + + return result; + } finally { + + } + } + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/LineBreakIteratorUtf16.d.ts b/ffi/capi/bindings/js/LineBreakIteratorUtf16.d.ts index 11e453e7d36..a945b8b44c8 100644 --- a/ffi/capi/bindings/js/LineBreakIteratorUtf16.d.ts +++ b/ffi/capi/bindings/js/LineBreakIteratorUtf16.d.ts @@ -1,18 +1,19 @@ -import { i32 } from "./diplomat-runtime" +// generated by diplomat-tool +import type { pointer, char } from "./diplomat-runtime.d.ts"; -/** - * See the {@link https://docs.rs/icu/latest/icu/segmenter/struct.LineBreakIterator.html Rust documentation for `LineBreakIterator`} for more information. - - * Additional information: {@link https://docs.rs/icu/latest/icu/segmenter/type.LineBreakIteratorUtf16.html 1} - */ +/** See the [Rust documentation for `LineBreakIterator`](https://docs.rs/icu/latest/icu/segmenter/struct.LineBreakIterator.html) for more information. +* +*Additional information: [1](https://docs.rs/icu/latest/icu/segmenter/type.LineBreakIteratorUtf16.html) +*/ export class LineBreakIteratorUtf16 { + + + get ffiValue(): pointer; + - /** + next(): number; - * Finds the next breakpoint. Returns -1 if at the end of the string or if the index is out of range of a 32-bit signed integer. + - * See the {@link https://docs.rs/icu/latest/icu/segmenter/struct.LineBreakIterator.html#method.next Rust documentation for `next`} for more information. - */ - next(): i32; -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/LineBreakIteratorUtf16.mjs b/ffi/capi/bindings/js/LineBreakIteratorUtf16.mjs index a3b9ea1bba4..12d40689528 100644 --- a/ffi/capi/bindings/js/LineBreakIteratorUtf16.mjs +++ b/ffi/capi/bindings/js/LineBreakIteratorUtf16.mjs @@ -1,21 +1,54 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" +// generated by diplomat-tool +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -const LineBreakIteratorUtf16_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XLineBreakIteratorUtf16_destroy(underlying); -}); +/** See the [Rust documentation for `LineBreakIterator`](https://docs.rs/icu/latest/icu/segmenter/struct.LineBreakIterator.html) for more information. +* +*Additional information: [1](https://docs.rs/icu/latest/icu/segmenter/type.LineBreakIteratorUtf16.html) +*/ + +const LineBreakIteratorUtf16_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XLineBreakIteratorUtf16_destroy(ptr); +}); export class LineBreakIteratorUtf16 { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - LineBreakIteratorUtf16_box_destroy_registry.register(this, underlying); + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + #aEdge = []; + + + constructor(ptr, selfEdge, aEdge) { + + + this.#aEdge = aEdge; + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + LineBreakIteratorUtf16_box_destroy_registry.register(this, this.#ptr); + } + + get ffiValue() { + return this.#ptr; } - } - next() { - return wasm.ICU4XLineBreakIteratorUtf16_next(this.underlying); - } -} + + next() { + const result = wasm.ICU4XLineBreakIteratorUtf16_next(this.ffiValue); + + try { + + return result; + } finally { + + } + } + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/LineBreakIteratorUtf8.d.ts b/ffi/capi/bindings/js/LineBreakIteratorUtf8.d.ts index 57fcbc2e0bb..2aae73cced0 100644 --- a/ffi/capi/bindings/js/LineBreakIteratorUtf8.d.ts +++ b/ffi/capi/bindings/js/LineBreakIteratorUtf8.d.ts @@ -1,18 +1,19 @@ -import { i32 } from "./diplomat-runtime" +// generated by diplomat-tool +import type { pointer, char } from "./diplomat-runtime.d.ts"; -/** - * See the {@link https://docs.rs/icu/latest/icu/segmenter/struct.LineBreakIterator.html Rust documentation for `LineBreakIterator`} for more information. - - * Additional information: {@link https://docs.rs/icu/latest/icu/segmenter/type.LineBreakIteratorPotentiallyIllFormedUtf8.html 1} - */ +/** See the [Rust documentation for `LineBreakIterator`](https://docs.rs/icu/latest/icu/segmenter/struct.LineBreakIterator.html) for more information. +* +*Additional information: [1](https://docs.rs/icu/latest/icu/segmenter/type.LineBreakIteratorPotentiallyIllFormedUtf8.html) +*/ export class LineBreakIteratorUtf8 { + + + get ffiValue(): pointer; + - /** + next(): number; - * Finds the next breakpoint. Returns -1 if at the end of the string or if the index is out of range of a 32-bit signed integer. + - * See the {@link https://docs.rs/icu/latest/icu/segmenter/struct.LineBreakIterator.html#method.next Rust documentation for `next`} for more information. - */ - next(): i32; -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/LineBreakIteratorUtf8.mjs b/ffi/capi/bindings/js/LineBreakIteratorUtf8.mjs index ea1993545e6..c4f317a21cc 100644 --- a/ffi/capi/bindings/js/LineBreakIteratorUtf8.mjs +++ b/ffi/capi/bindings/js/LineBreakIteratorUtf8.mjs @@ -1,21 +1,54 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" +// generated by diplomat-tool +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -const LineBreakIteratorUtf8_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XLineBreakIteratorUtf8_destroy(underlying); -}); +/** See the [Rust documentation for `LineBreakIterator`](https://docs.rs/icu/latest/icu/segmenter/struct.LineBreakIterator.html) for more information. +* +*Additional information: [1](https://docs.rs/icu/latest/icu/segmenter/type.LineBreakIteratorPotentiallyIllFormedUtf8.html) +*/ + +const LineBreakIteratorUtf8_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XLineBreakIteratorUtf8_destroy(ptr); +}); export class LineBreakIteratorUtf8 { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - LineBreakIteratorUtf8_box_destroy_registry.register(this, underlying); + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + #aEdge = []; + + + constructor(ptr, selfEdge, aEdge) { + + + this.#aEdge = aEdge; + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + LineBreakIteratorUtf8_box_destroy_registry.register(this, this.#ptr); + } + + get ffiValue() { + return this.#ptr; } - } - next() { - return wasm.ICU4XLineBreakIteratorUtf8_next(this.underlying); - } -} + + next() { + const result = wasm.ICU4XLineBreakIteratorUtf8_next(this.ffiValue); + + try { + + return result; + } finally { + + } + } + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/LineBreakOptions.d.ts b/ffi/capi/bindings/js/LineBreakOptions.d.ts new file mode 100644 index 00000000000..bdc83510436 --- /dev/null +++ b/ffi/capi/bindings/js/LineBreakOptions.d.ts @@ -0,0 +1,19 @@ +// generated by diplomat-tool +import type { LineBreakStrictness } from "./LineBreakStrictness" +import type { LineBreakWordOption } from "./LineBreakWordOption" +import type { pointer, char } from "./diplomat-runtime.d.ts"; + + +/** See the [Rust documentation for `LineBreakOptions`](https://docs.rs/icu/latest/icu/segmenter/struct.LineBreakOptions.html) for more information. +*/ +export class LineBreakOptions { + get strictness() : LineBreakStrictness; + set strictness(value: LineBreakStrictness); + get wordOption() : LineBreakWordOption; + set wordOption(value: LineBreakWordOption); + get jaZh() : boolean; + set jaZh(value: boolean); + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/LineBreakOptions.mjs b/ffi/capi/bindings/js/LineBreakOptions.mjs new file mode 100644 index 00000000000..3e88ff1d0d0 --- /dev/null +++ b/ffi/capi/bindings/js/LineBreakOptions.mjs @@ -0,0 +1,60 @@ +// generated by diplomat-tool +import { LineBreakStrictness } from "./LineBreakStrictness.mjs" +import { LineBreakWordOption } from "./LineBreakWordOption.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; + + +/** See the [Rust documentation for `LineBreakOptions`](https://docs.rs/icu/latest/icu/segmenter/struct.LineBreakOptions.html) for more information. +*/ +export class LineBreakOptions { + #strictness; + get strictness() { + return this.#strictness; + } + set strictness(value) { + this.#strictness = value; + } + #wordOption; + get wordOption() { + return this.#wordOption; + } + set wordOption(value) { + this.#wordOption = value; + } + #jaZh; + get jaZh() { + return this.#jaZh; + } + set jaZh(value) { + this.#jaZh = value; + } + + // Return this struct in FFI function friendly format. + // Returns an array that can be expanded with spread syntax (...) + + _intoFFI( + slice_cleanup_callbacks, + appendArrayMap + ) { + return [this.#strictness.ffiValue, this.#wordOption.ffiValue, this.#jaZh] + } + + // 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. + _fromFFI(ptr) { + const strictnessDeref = diplomatRuntime.enumDiscriminant(wasm, ptr); + this.#strictness = LineBreakStrictness[Array.from(LineBreakStrictness.values.keys())[strictnessDeref]]; + const wordOptionDeref = diplomatRuntime.enumDiscriminant(wasm, ptr + 4); + this.#wordOption = LineBreakWordOption[Array.from(LineBreakWordOption.values.keys())[wordOptionDeref]]; + const jaZhDeref = (new Uint8Array(wasm.memory.buffer, ptr + 8, 1))[0] == 1; + this.#jaZh = jaZhDeref; + + return this; + } + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/LineBreakOptionsV1.d.ts b/ffi/capi/bindings/js/LineBreakOptionsV1.d.ts deleted file mode 100644 index baaf28edfde..00000000000 --- a/ffi/capi/bindings/js/LineBreakOptionsV1.d.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { LineBreakStrictness } from "./LineBreakStrictness"; -import { LineBreakWordOption } from "./LineBreakWordOption"; - -/** - - * See the {@link https://docs.rs/icu/latest/icu/segmenter/struct.LineBreakOptions.html Rust documentation for `LineBreakOptions`} for more information. - */ -export class LineBreakOptionsV1 { - strictness: LineBreakStrictness; - word_option: LineBreakWordOption; - ja_zh: boolean; -} diff --git a/ffi/capi/bindings/js/LineBreakOptionsV1.mjs b/ffi/capi/bindings/js/LineBreakOptionsV1.mjs deleted file mode 100644 index c55b543c927..00000000000 --- a/ffi/capi/bindings/js/LineBreakOptionsV1.mjs +++ /dev/null @@ -1,12 +0,0 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" -import { LineBreakStrictness_js_to_rust, LineBreakStrictness_rust_to_js } from "./LineBreakStrictness.mjs" -import { LineBreakWordOption_js_to_rust, LineBreakWordOption_rust_to_js } from "./LineBreakWordOption.mjs" - -export class LineBreakOptionsV1 { - constructor(underlying) { - this.strictness = LineBreakStrictness_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, underlying)]; - this.word_option = LineBreakWordOption_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, underlying + 4)]; - this.ja_zh = (new Uint8Array(wasm.memory.buffer, underlying + 8, 1))[0] == 1; - } -} diff --git a/ffi/capi/bindings/js/LineBreakStrictness.d.ts b/ffi/capi/bindings/js/LineBreakStrictness.d.ts index f851928b711..041814185b4 100644 --- a/ffi/capi/bindings/js/LineBreakStrictness.d.ts +++ b/ffi/capi/bindings/js/LineBreakStrictness.d.ts @@ -1,19 +1,25 @@ +// generated by diplomat-tool +import type { pointer, char } from "./diplomat-runtime.d.ts"; + +// Base enumerator definition +/** See the [Rust documentation for `LineBreakStrictness`](https://docs.rs/icu/latest/icu/segmenter/enum.LineBreakStrictness.html) for more information. +*/ +export class LineBreakStrictness { + constructor(value : LineBreakStrictness | string); + + get value() : string; + + get ffiValue() : number; + + static Loose : LineBreakStrictness; + + static Normal : LineBreakStrictness; + + static Strict : LineBreakStrictness; + + static Anywhere : LineBreakStrictness; + + + -/** - - * See the {@link https://docs.rs/icu/latest/icu/segmenter/enum.LineBreakStrictness.html Rust documentation for `LineBreakStrictness`} for more information. - */ -export enum LineBreakStrictness { - /** - */ - Loose = 'Loose', - /** - */ - Normal = 'Normal', - /** - */ - Strict = 'Strict', - /** - */ - Anywhere = 'Anywhere', } \ No newline at end of file diff --git a/ffi/capi/bindings/js/LineBreakStrictness.mjs b/ffi/capi/bindings/js/LineBreakStrictness.mjs index 5ec24055239..04dc8203b56 100644 --- a/ffi/capi/bindings/js/LineBreakStrictness.mjs +++ b/ffi/capi/bindings/js/LineBreakStrictness.mjs @@ -1,23 +1,50 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" - -export const LineBreakStrictness_js_to_rust = { - "Loose": 0, - "Normal": 1, - "Strict": 2, - "Anywhere": 3, -}; - -export const LineBreakStrictness_rust_to_js = { - [0]: "Loose", - [1]: "Normal", - [2]: "Strict", - [3]: "Anywhere", -}; - -export const LineBreakStrictness = { - "Loose": "Loose", - "Normal": "Normal", - "Strict": "Strict", - "Anywhere": "Anywhere", -}; +// generated by diplomat-tool +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; + +// Base enumerator definition +/** See the [Rust documentation for `LineBreakStrictness`](https://docs.rs/icu/latest/icu/segmenter/enum.LineBreakStrictness.html) for more information. +*/ +export class LineBreakStrictness { + #value = undefined; + + static values = new Map([ + ["Loose", 0], + ["Normal", 1], + ["Strict", 2], + ["Anywhere", 3] + ]); + constructor(value) { + if (value instanceof LineBreakStrictness) { + this.#value = value.value; + return; + } + + if (LineBreakStrictness.values.has(value)) { + this.#value = value; + return; + } + + throw TypeError(value + " is not a LineBreakStrictness and does not correspond to any of its enumerator values."); + } + + get value() { + return this.#value; + } + + get ffiValue() { + return LineBreakStrictness.values.get(this.#value); + } + + static Loose = new LineBreakStrictness("Loose"); + + static Normal = new LineBreakStrictness("Normal"); + + static Strict = new LineBreakStrictness("Strict"); + + static Anywhere = new LineBreakStrictness("Anywhere"); + + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/LineBreakWordOption.d.ts b/ffi/capi/bindings/js/LineBreakWordOption.d.ts index 03fd22e9c9a..716811530f2 100644 --- a/ffi/capi/bindings/js/LineBreakWordOption.d.ts +++ b/ffi/capi/bindings/js/LineBreakWordOption.d.ts @@ -1,16 +1,23 @@ +// generated by diplomat-tool +import type { pointer, char } from "./diplomat-runtime.d.ts"; + +// Base enumerator definition +/** See the [Rust documentation for `LineBreakWordOption`](https://docs.rs/icu/latest/icu/segmenter/enum.LineBreakWordOption.html) for more information. +*/ +export class LineBreakWordOption { + constructor(value : LineBreakWordOption | string); + + get value() : string; + + get ffiValue() : number; + + static Normal : LineBreakWordOption; + + static BreakAll : LineBreakWordOption; + + static KeepAll : LineBreakWordOption; + + + -/** - - * See the {@link https://docs.rs/icu/latest/icu/segmenter/enum.LineBreakWordOption.html Rust documentation for `LineBreakWordOption`} for more information. - */ -export enum LineBreakWordOption { - /** - */ - Normal = 'Normal', - /** - */ - BreakAll = 'BreakAll', - /** - */ - KeepAll = 'KeepAll', } \ No newline at end of file diff --git a/ffi/capi/bindings/js/LineBreakWordOption.mjs b/ffi/capi/bindings/js/LineBreakWordOption.mjs index 24ce73db799..225f9edfd8c 100644 --- a/ffi/capi/bindings/js/LineBreakWordOption.mjs +++ b/ffi/capi/bindings/js/LineBreakWordOption.mjs @@ -1,20 +1,47 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" - -export const LineBreakWordOption_js_to_rust = { - "Normal": 0, - "BreakAll": 1, - "KeepAll": 2, -}; - -export const LineBreakWordOption_rust_to_js = { - [0]: "Normal", - [1]: "BreakAll", - [2]: "KeepAll", -}; - -export const LineBreakWordOption = { - "Normal": "Normal", - "BreakAll": "BreakAll", - "KeepAll": "KeepAll", -}; +// generated by diplomat-tool +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; + +// Base enumerator definition +/** See the [Rust documentation for `LineBreakWordOption`](https://docs.rs/icu/latest/icu/segmenter/enum.LineBreakWordOption.html) for more information. +*/ +export class LineBreakWordOption { + #value = undefined; + + static values = new Map([ + ["Normal", 0], + ["BreakAll", 1], + ["KeepAll", 2] + ]); + constructor(value) { + if (value instanceof LineBreakWordOption) { + this.#value = value.value; + return; + } + + if (LineBreakWordOption.values.has(value)) { + this.#value = value; + return; + } + + throw TypeError(value + " is not a LineBreakWordOption and does not correspond to any of its enumerator values."); + } + + get value() { + return this.#value; + } + + get ffiValue() { + return LineBreakWordOption.values.get(this.#value); + } + + static Normal = new LineBreakWordOption("Normal"); + + static BreakAll = new LineBreakWordOption("BreakAll"); + + static KeepAll = new LineBreakWordOption("KeepAll"); + + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/LineSegmenter.d.ts b/ffi/capi/bindings/js/LineSegmenter.d.ts index eeb923ebe2b..476d7724f9b 100644 --- a/ffi/capi/bindings/js/LineSegmenter.d.ts +++ b/ffi/capi/bindings/js/LineSegmenter.d.ts @@ -1,98 +1,34 @@ -import { FFIError } from "./diplomat-runtime" -import { DataError } from "./DataError"; -import { DataProvider } from "./DataProvider"; -import { LineBreakIteratorLatin1 } from "./LineBreakIteratorLatin1"; -import { LineBreakIteratorUtf16 } from "./LineBreakIteratorUtf16"; -import { LineBreakIteratorUtf8 } from "./LineBreakIteratorUtf8"; -import { LineBreakOptionsV1 } from "./LineBreakOptionsV1"; +// generated by diplomat-tool +import type { DataProvider } from "./DataProvider" +import type { LineBreakIteratorUtf16 } from "./LineBreakIteratorUtf16" +import type { LineBreakOptions } from "./LineBreakOptions" +import type { pointer, char } from "./diplomat-runtime.d.ts"; -/** - * An ICU4X line-break segmenter, capable of finding breakpoints in strings. - - * See the {@link https://docs.rs/icu/latest/icu/segmenter/struct.LineSegmenter.html Rust documentation for `LineSegmenter`} for more information. - */ +/** An ICU4X line-break segmenter, capable of finding breakpoints in strings. +* +*See the [Rust documentation for `LineSegmenter`](https://docs.rs/icu/latest/icu/segmenter/struct.LineSegmenter.html) for more information. +*/ export class LineSegmenter { + - /** - - * Construct a {@link LineSegmenter `LineSegmenter`} with default options. It automatically loads the best available payload data for Burmese, Khmer, Lao, and Thai. - - * See the {@link https://docs.rs/icu/latest/icu/segmenter/struct.LineSegmenter.html#method.new_auto Rust documentation for `new_auto`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static create_auto(provider: DataProvider): LineSegmenter | never; - - /** - - * Construct a {@link LineSegmenter `LineSegmenter`} with default options and LSTM payload data for Burmese, Khmer, Lao, and Thai. - - * See the {@link https://docs.rs/icu/latest/icu/segmenter/struct.LineSegmenter.html#method.new_lstm Rust documentation for `new_lstm`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static create_lstm(provider: DataProvider): LineSegmenter | never; - - /** - - * Construct a {@link LineSegmenter `LineSegmenter`} with default options and dictionary payload data for Burmese, Khmer, Lao, and Thai.. - - * See the {@link https://docs.rs/icu/latest/icu/segmenter/struct.LineSegmenter.html#method.new_dictionary Rust documentation for `new_dictionary`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static create_dictionary(provider: DataProvider): LineSegmenter | never; - - /** - - * Construct a {@link LineSegmenter `LineSegmenter`} with custom options. It automatically loads the best available payload data for Burmese, Khmer, Lao, and Thai. - - * See the {@link https://docs.rs/icu/latest/icu/segmenter/struct.LineSegmenter.html#method.new_auto_with_options Rust documentation for `new_auto_with_options`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static create_auto_with_options_v1(provider: DataProvider, options: LineBreakOptionsV1): LineSegmenter | never; - - /** - - * Construct a {@link LineSegmenter `LineSegmenter`} with custom options and LSTM payload data for Burmese, Khmer, Lao, and Thai. - - * See the {@link https://docs.rs/icu/latest/icu/segmenter/struct.LineSegmenter.html#method.new_lstm_with_options Rust documentation for `new_lstm_with_options`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static create_lstm_with_options_v1(provider: DataProvider, options: LineBreakOptionsV1): LineSegmenter | never; - - /** - - * Construct a {@link LineSegmenter `LineSegmenter`} with custom options and dictionary payload data for Burmese, Khmer, Lao, and Thai. - - * See the {@link https://docs.rs/icu/latest/icu/segmenter/struct.LineSegmenter.html#method.new_dictionary_with_options Rust documentation for `new_dictionary_with_options`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static create_dictionary_with_options_v1(provider: DataProvider, options: LineBreakOptionsV1): LineSegmenter | never; - - /** + get ffiValue(): pointer; - * Segments a string. - * Ill-formed input is treated as if errors had been replaced with REPLACEMENT CHARACTERs according to the WHATWG Encoding Standard. + static createAuto(provider: DataProvider): LineSegmenter; - * See the {@link https://docs.rs/icu/latest/icu/segmenter/struct.LineSegmenter.html#method.segment_utf8 Rust documentation for `segment_utf8`} for more information. - */ - segment_utf8(input: string): LineBreakIteratorUtf8; + static createLstm(provider: DataProvider): LineSegmenter; - /** + static createDictionary(provider: DataProvider): LineSegmenter; - * Segments a string. + static autoWithOptions(provider: DataProvider, options: LineBreakOptions): LineSegmenter; - * Ill-formed input is treated as if errors had been replaced with REPLACEMENT CHARACTERs according to the WHATWG Encoding Standard. + static lstmWithOptions(provider: DataProvider, options: LineBreakOptions): LineSegmenter; - * See the {@link https://docs.rs/icu/latest/icu/segmenter/struct.LineSegmenter.html#method.segment_utf16 Rust documentation for `segment_utf16`} for more information. - */ - segment_utf16(input: string): LineBreakIteratorUtf16; + static dictionaryWithOptions(provider: DataProvider, options: LineBreakOptions): LineSegmenter; - /** + segment(input: string): LineBreakIteratorUtf16; - * Segments a Latin-1 string. + - * See the {@link https://docs.rs/icu/latest/icu/segmenter/struct.LineSegmenter.html#method.segment_latin1 Rust documentation for `segment_latin1`} for more information. - */ - segment_latin1(input: Uint8Array): LineBreakIteratorLatin1; -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/LineSegmenter.mjs b/ffi/capi/bindings/js/LineSegmenter.mjs index cb14a702032..5203e8c1971 100644 --- a/ffi/capi/bindings/js/LineSegmenter.mjs +++ b/ffi/capi/bindings/js/LineSegmenter.mjs @@ -1,155 +1,192 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" -import { DataError_js_to_rust, DataError_rust_to_js } from "./DataError.mjs" -import { LineBreakIteratorLatin1 } from "./LineBreakIteratorLatin1.mjs" +// generated by diplomat-tool +import { DataError } from "./DataError.mjs" +import { DataProvider } from "./DataProvider.mjs" import { LineBreakIteratorUtf16 } from "./LineBreakIteratorUtf16.mjs" -import { LineBreakIteratorUtf8 } from "./LineBreakIteratorUtf8.mjs" -import { LineBreakStrictness_js_to_rust, LineBreakStrictness_rust_to_js } from "./LineBreakStrictness.mjs" -import { LineBreakWordOption_js_to_rust, LineBreakWordOption_rust_to_js } from "./LineBreakWordOption.mjs" +import { LineBreakOptions } from "./LineBreakOptions.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -const LineSegmenter_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XLineSegmenter_destroy(underlying); -}); +/** An ICU4X line-break segmenter, capable of finding breakpoints in strings. +* +*See the [Rust documentation for `LineSegmenter`](https://docs.rs/icu/latest/icu/segmenter/struct.LineSegmenter.html) for more information. +*/ + +const LineSegmenter_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XLineSegmenter_destroy(ptr); +}); export class LineSegmenter { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - LineSegmenter_box_destroy_registry.register(this, underlying); + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + + constructor(ptr, selfEdge) { + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + LineSegmenter_box_destroy_registry.register(this, this.#ptr); } - } - static create_auto(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XLineSegmenter_create_auto(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new LineSegmenter(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } + get ffiValue() { + return this.#ptr; + } + + + static createAuto(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XLineSegmenter_create_auto(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new LineSegmenter(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } - static create_lstm(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XLineSegmenter_create_lstm(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new LineSegmenter(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } + static createLstm(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XLineSegmenter_create_lstm(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new LineSegmenter(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } - static create_dictionary(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XLineSegmenter_create_dictionary(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new LineSegmenter(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } + static createDictionary(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XLineSegmenter_create_dictionary(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new LineSegmenter(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } - static create_auto_with_options_v1(arg_provider, arg_options) { - const field_strictness_arg_options = arg_options["strictness"]; - const field_word_option_arg_options = arg_options["word_option"]; - const field_ja_zh_arg_options = arg_options["ja_zh"]; - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XLineSegmenter_create_auto_with_options_v1(diplomat_receive_buffer, arg_provider.underlying, LineBreakStrictness_js_to_rust[field_strictness_arg_options], LineBreakWordOption_js_to_rust[field_word_option_arg_options], field_ja_zh_arg_options); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new LineSegmenter(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } + static autoWithOptions(provider, options) { + + let slice_cleanup_callbacks = []; + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XLineSegmenter_create_auto_with_options_v1(diplomat_receive_buffer, provider.ffiValue, ...options._intoFFI(slice_cleanup_callbacks, {})); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new LineSegmenter(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + for (let cleanup of slice_cleanup_callbacks) { + cleanup(); + } + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } - static create_lstm_with_options_v1(arg_provider, arg_options) { - const field_strictness_arg_options = arg_options["strictness"]; - const field_word_option_arg_options = arg_options["word_option"]; - const field_ja_zh_arg_options = arg_options["ja_zh"]; - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XLineSegmenter_create_lstm_with_options_v1(diplomat_receive_buffer, arg_provider.underlying, LineBreakStrictness_js_to_rust[field_strictness_arg_options], LineBreakWordOption_js_to_rust[field_word_option_arg_options], field_ja_zh_arg_options); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new LineSegmenter(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } + static lstmWithOptions(provider, options) { + + let slice_cleanup_callbacks = []; + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XLineSegmenter_create_lstm_with_options_v1(diplomat_receive_buffer, provider.ffiValue, ...options._intoFFI(slice_cleanup_callbacks, {})); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new LineSegmenter(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + for (let cleanup of slice_cleanup_callbacks) { + cleanup(); + } + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } - static create_dictionary_with_options_v1(arg_provider, arg_options) { - const field_strictness_arg_options = arg_options["strictness"]; - const field_word_option_arg_options = arg_options["word_option"]; - const field_ja_zh_arg_options = arg_options["ja_zh"]; - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XLineSegmenter_create_dictionary_with_options_v1(diplomat_receive_buffer, arg_provider.underlying, LineBreakStrictness_js_to_rust[field_strictness_arg_options], LineBreakWordOption_js_to_rust[field_word_option_arg_options], field_ja_zh_arg_options); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new LineSegmenter(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } + static dictionaryWithOptions(provider, options) { + + let slice_cleanup_callbacks = []; + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XLineSegmenter_create_dictionary_with_options_v1(diplomat_receive_buffer, provider.ffiValue, ...options._intoFFI(slice_cleanup_callbacks, {})); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new LineSegmenter(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + for (let cleanup of slice_cleanup_callbacks) { + cleanup(); + } + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } - segment_utf8(arg_input) { - const buf_arg_input = diplomatRuntime.DiplomatBuf.str8(wasm, arg_input); - const diplomat_out = new LineBreakIteratorUtf8(wasm.ICU4XLineSegmenter_segment_utf8(this.underlying, buf_arg_input.ptr, buf_arg_input.size), true, [this, buf_arg_input]); - buf_arg_input.garbageCollect(); - return diplomat_out; - } + segment(input) { + + const inputSlice = diplomatRuntime.DiplomatBuf.str16(wasm, input); + + // This lifetime edge depends on lifetimes 'a + let aEdges = [this, inputSlice]; + const result = wasm.ICU4XLineSegmenter_segment_utf16(this.ffiValue, inputSlice.ptr, inputSlice.size); + + try { + + return new LineBreakIteratorUtf16(result, [], aEdges); + } finally { + + inputSlice.garbageCollect(); + + } + } - segment_utf16(arg_input) { - const buf_arg_input = diplomatRuntime.DiplomatBuf.str16(wasm, arg_input); - const diplomat_out = new LineBreakIteratorUtf16(wasm.ICU4XLineSegmenter_segment_utf16(this.underlying, buf_arg_input.ptr, buf_arg_input.size), true, [this, buf_arg_input]); - buf_arg_input.garbageCollect(); - return diplomat_out; - } + - segment_latin1(arg_input) { - const buf_arg_input = diplomatRuntime.DiplomatBuf.slice(wasm, arg_input, "u8"); - const diplomat_out = new LineBreakIteratorLatin1(wasm.ICU4XLineSegmenter_segment_latin1(this.underlying, buf_arg_input.ptr, buf_arg_input.size), true, [this, buf_arg_input]); - buf_arg_input.garbageCollect(); - return diplomat_out; - } -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/List.d.ts b/ffi/capi/bindings/js/List.d.ts deleted file mode 100644 index 0ababd067e5..00000000000 --- a/ffi/capi/bindings/js/List.d.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { usize } from "./diplomat-runtime" - -/** - - * A list of strings - */ -export class List { - - /** - - * Create a new list of strings - */ - static create(): List; - - /** - - * Create a new list of strings with preallocated space to hold at least `capacity` elements - */ - static create_with_capacity(capacity: usize): List; - - /** - - * Push a string to the list - - * Ill-formed input is treated as if errors had been replaced with REPLACEMENT CHARACTERs according to the WHATWG Encoding Standard. - */ - push(val: string): void; - - /** - - * The number of elements in this list - */ - len(): usize; - - /** - - * Whether this list is empty - */ - is_empty(): boolean; -} diff --git a/ffi/capi/bindings/js/List.mjs b/ffi/capi/bindings/js/List.mjs deleted file mode 100644 index ebeef2312cc..00000000000 --- a/ffi/capi/bindings/js/List.mjs +++ /dev/null @@ -1,39 +0,0 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" - -const List_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XList_destroy(underlying); -}); - -export class List { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - List_box_destroy_registry.register(this, underlying); - } - } - - static create() { - return new List(wasm.ICU4XList_create(), true, []); - } - - static create_with_capacity(arg_capacity) { - return new List(wasm.ICU4XList_create_with_capacity(arg_capacity), true, []); - } - - push(arg_val) { - const buf_arg_val = diplomatRuntime.DiplomatBuf.str8(wasm, arg_val); - wasm.ICU4XList_push(this.underlying, buf_arg_val.ptr, buf_arg_val.size); - buf_arg_val.free(); - } - - len() { - return wasm.ICU4XList_len(this.underlying); - } - - is_empty() { - return wasm.ICU4XList_is_empty(this.underlying); - } -} diff --git a/ffi/capi/bindings/js/ListFormatter.d.ts b/ffi/capi/bindings/js/ListFormatter.d.ts index 2cfbe24a896..bc41a4200c7 100644 --- a/ffi/capi/bindings/js/ListFormatter.d.ts +++ b/ffi/capi/bindings/js/ListFormatter.d.ts @@ -1,46 +1,26 @@ -import { FFIError } from "./diplomat-runtime" -import { DataError } from "./DataError"; -import { DataProvider } from "./DataProvider"; -import { List } from "./List"; -import { ListLength } from "./ListLength"; -import { Locale } from "./Locale"; +// generated by diplomat-tool +import type { DataProvider } from "./DataProvider" +import type { ListLength } from "./ListLength" +import type { Locale } from "./Locale" +import type { pointer, char } from "./diplomat-runtime.d.ts"; -/** - * See the {@link https://docs.rs/icu/latest/icu/list/struct.ListFormatter.html Rust documentation for `ListFormatter`} for more information. - */ +/** See the [Rust documentation for `ListFormatter`](https://docs.rs/icu/latest/icu/list/struct.ListFormatter.html) for more information. +*/ export class ListFormatter { + - /** + get ffiValue(): pointer; - * Construct a new ListFormatter instance for And patterns - * See the {@link https://docs.rs/icu/latest/icu/list/struct.ListFormatter.html#method.try_new_and_with_length Rust documentation for `try_new_and_with_length`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static create_and_with_length(provider: DataProvider, locale: Locale, length: ListLength): ListFormatter | never; + static createAndWithLength(provider: DataProvider, locale: Locale, length: ListLength): ListFormatter; - /** + static createOrWithLength(provider: DataProvider, locale: Locale, length: ListLength): ListFormatter; - * Construct a new ListFormatter instance for And patterns + static createUnitWithLength(provider: DataProvider, locale: Locale, length: ListLength): ListFormatter; - * See the {@link https://docs.rs/icu/latest/icu/list/struct.ListFormatter.html#method.try_new_or_with_length Rust documentation for `try_new_or_with_length`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static create_or_with_length(provider: DataProvider, locale: Locale, length: ListLength): ListFormatter | never; + format(list: Array): string; - /** + - * Construct a new ListFormatter instance for And patterns - - * See the {@link https://docs.rs/icu/latest/icu/list/struct.ListFormatter.html#method.try_new_unit_with_length Rust documentation for `try_new_unit_with_length`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static create_unit_with_length(provider: DataProvider, locale: Locale, length: ListLength): ListFormatter | never; - - /** - - * See the {@link https://docs.rs/icu/latest/icu/list/struct.ListFormatter.html#method.format Rust documentation for `format`} for more information. - */ - format(list: List): string; -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/ListFormatter.mjs b/ffi/capi/bindings/js/ListFormatter.mjs index 83d5a11d0b8..295556922e7 100644 --- a/ffi/capi/bindings/js/ListFormatter.mjs +++ b/ffi/capi/bindings/js/ListFormatter.mjs @@ -1,76 +1,116 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" -import { DataError_js_to_rust, DataError_rust_to_js } from "./DataError.mjs" -import { ListLength_js_to_rust, ListLength_rust_to_js } from "./ListLength.mjs" +// generated by diplomat-tool +import { DataError } from "./DataError.mjs" +import { DataProvider } from "./DataProvider.mjs" +import { ListLength } from "./ListLength.mjs" +import { Locale } from "./Locale.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -const ListFormatter_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XListFormatter_destroy(underlying); -}); +/** See the [Rust documentation for `ListFormatter`](https://docs.rs/icu/latest/icu/list/struct.ListFormatter.html) for more information. +*/ + +const ListFormatter_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XListFormatter_destroy(ptr); +}); export class ListFormatter { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - ListFormatter_box_destroy_registry.register(this, underlying); + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + + constructor(ptr, selfEdge) { + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + ListFormatter_box_destroy_registry.register(this, this.#ptr); + } + + get ffiValue() { + return this.#ptr; } - } - static create_and_with_length(arg_provider, arg_locale, arg_length) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XListFormatter_create_and_with_length(diplomat_receive_buffer, arg_provider.underlying, arg_locale.underlying, ListLength_js_to_rust[arg_length]); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new ListFormatter(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - static create_or_with_length(arg_provider, arg_locale, arg_length) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XListFormatter_create_or_with_length(diplomat_receive_buffer, arg_provider.underlying, arg_locale.underlying, ListLength_js_to_rust[arg_length]); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new ListFormatter(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } + static createAndWithLength(provider, locale, length) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XListFormatter_create_and_with_length(diplomat_receive_buffer, provider.ffiValue, locale.ffiValue, length.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new ListFormatter(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static createOrWithLength(provider, locale, length) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XListFormatter_create_or_with_length(diplomat_receive_buffer, provider.ffiValue, locale.ffiValue, length.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new ListFormatter(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static createUnitWithLength(provider, locale, length) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XListFormatter_create_unit_with_length(diplomat_receive_buffer, provider.ffiValue, locale.ffiValue, length.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new ListFormatter(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + format(list) { + + const listSlice = diplomatRuntime.DiplomatBuf.str16(wasm, list); + + const write = wasm.diplomat_buffer_write_create(0); + wasm.ICU4XListFormatter_format_utf16(this.ffiValue, listSlice.ptr, listSlice.size, write); + + try { + + return diplomatRuntime.readString8(wasm, wasm.diplomat_buffer_write_get_bytes(write), wasm.diplomat_buffer_write_len(write)); + } finally { + + listSlice.free(); + + wasm.diplomat_buffer_write_destroy(write); + + } + } - static create_unit_with_length(arg_provider, arg_locale, arg_length) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XListFormatter_create_unit_with_length(diplomat_receive_buffer, arg_provider.underlying, arg_locale.underlying, ListLength_js_to_rust[arg_length]); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new ListFormatter(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } + - format(arg_list) { - return diplomatRuntime.withDiplomatWrite(wasm, (write) => { - return wasm.ICU4XListFormatter_format(this.underlying, arg_list.underlying, write); - }); - } -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/ListLength.d.ts b/ffi/capi/bindings/js/ListLength.d.ts index dd114302c66..edd5b128b3a 100644 --- a/ffi/capi/bindings/js/ListLength.d.ts +++ b/ffi/capi/bindings/js/ListLength.d.ts @@ -1,16 +1,23 @@ +// generated by diplomat-tool +import type { pointer, char } from "./diplomat-runtime.d.ts"; + +// Base enumerator definition +/** See the [Rust documentation for `ListLength`](https://docs.rs/icu/latest/icu/list/enum.ListLength.html) for more information. +*/ +export class ListLength { + constructor(value : ListLength | string); + + get value() : string; + + get ffiValue() : number; + + static Wide : ListLength; + + static Short : ListLength; + + static Narrow : ListLength; + + + -/** - - * See the {@link https://docs.rs/icu/latest/icu/list/enum.ListLength.html Rust documentation for `ListLength`} for more information. - */ -export enum ListLength { - /** - */ - Wide = 'Wide', - /** - */ - Short = 'Short', - /** - */ - Narrow = 'Narrow', } \ No newline at end of file diff --git a/ffi/capi/bindings/js/ListLength.mjs b/ffi/capi/bindings/js/ListLength.mjs index bc54b93f658..53497ce9c2b 100644 --- a/ffi/capi/bindings/js/ListLength.mjs +++ b/ffi/capi/bindings/js/ListLength.mjs @@ -1,20 +1,47 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" - -export const ListLength_js_to_rust = { - "Wide": 0, - "Short": 1, - "Narrow": 2, -}; - -export const ListLength_rust_to_js = { - [0]: "Wide", - [1]: "Short", - [2]: "Narrow", -}; - -export const ListLength = { - "Wide": "Wide", - "Short": "Short", - "Narrow": "Narrow", -}; +// generated by diplomat-tool +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; + +// Base enumerator definition +/** See the [Rust documentation for `ListLength`](https://docs.rs/icu/latest/icu/list/enum.ListLength.html) for more information. +*/ +export class ListLength { + #value = undefined; + + static values = new Map([ + ["Wide", 0], + ["Short", 1], + ["Narrow", 2] + ]); + constructor(value) { + if (value instanceof ListLength) { + this.#value = value.value; + return; + } + + if (ListLength.values.has(value)) { + this.#value = value; + return; + } + + throw TypeError(value + " is not a ListLength and does not correspond to any of its enumerator values."); + } + + get value() { + return this.#value; + } + + get ffiValue() { + return ListLength.values.get(this.#value); + } + + static Wide = new ListLength("Wide"); + + static Short = new ListLength("Short"); + + static Narrow = new ListLength("Narrow"); + + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/Locale.d.ts b/ffi/capi/bindings/js/Locale.d.ts index 5a7cf66f2f0..9a4ebeeecec 100644 --- a/ffi/capi/bindings/js/Locale.d.ts +++ b/ffi/capi/bindings/js/Locale.d.ts @@ -1,143 +1,49 @@ -import { FFIError } from "./diplomat-runtime" -import { LocaleParseError } from "./LocaleParseError"; -import { Ordering } from "./Ordering"; +// generated by diplomat-tool +import type { pointer, char } from "./diplomat-runtime.d.ts"; -/** - * An ICU4X Locale, capable of representing strings like `"en-US"`. - - * See the {@link https://docs.rs/icu/latest/icu/locale/struct.Locale.html Rust documentation for `Locale`} for more information. - */ +/** An ICU4X Locale, capable of representing strings like `"en-US"`. +* +*See the [Rust documentation for `Locale`](https://docs.rs/icu/latest/icu/locale/struct.Locale.html) for more information. +*/ export class Locale { + - /** - - * Construct an {@link Locale `Locale`} from an locale identifier. - - * This will run the complete locale parsing algorithm. If code size and performance are critical and the locale is of a known shape (such as `aa-BB`) use `create_und`, `set_language`, `set_script`, and `set_region`. - - * See the {@link https://docs.rs/icu/latest/icu/locale/struct.Locale.html#method.try_from_str Rust documentation for `try_from_str`} for more information. - * @throws {@link FFIError}<{@link LocaleParseError}> - */ - static create_from_string(name: string): Locale | never; - - /** - - * Construct a default undefined {@link Locale `Locale`} "und". - - * See the {@link https://docs.rs/icu/latest/icu/locale/struct.Locale.html#associatedconstant.UND Rust documentation for `UND`} for more information. - */ - static create_und(): Locale; - - /** - - * Clones the {@link Locale `Locale`}. - - * See the {@link https://docs.rs/icu/latest/icu/locale/struct.Locale.html Rust documentation for `Locale`} for more information. - */ - clone(): Locale; - - /** - - * Returns a string representation of the `LanguageIdentifier` part of {@link Locale `Locale`}. - - * See the {@link https://docs.rs/icu/latest/icu/locale/struct.Locale.html#structfield.id Rust documentation for `id`} for more information. - */ - basename(): string; - - /** - - * Returns a string representation of the unicode extension. - - * See the {@link https://docs.rs/icu/latest/icu/locale/struct.Locale.html#structfield.extensions Rust documentation for `extensions`} for more information. - */ - get_unicode_extension(s: string): string | undefined; - - /** - - * Returns a string representation of {@link Locale `Locale`} language. - - * See the {@link https://docs.rs/icu/latest/icu/locale/struct.Locale.html#structfield.id Rust documentation for `id`} for more information. - */ - language(): string; - - /** - - * Set the language part of the {@link Locale `Locale`}. - - * See the {@link https://docs.rs/icu/latest/icu/locale/struct.Locale.html#method.try_from_str Rust documentation for `try_from_str`} for more information. - * @throws {@link FFIError}<{@link LocaleParseError}> - */ - set_language(s: string): void | never; - - /** - - * Returns a string representation of {@link Locale `Locale`} region. - - * See the {@link https://docs.rs/icu/latest/icu/locale/struct.Locale.html#structfield.id Rust documentation for `id`} for more information. - */ - region(): string | undefined; - - /** - - * Set the region part of the {@link Locale `Locale`}. - - * See the {@link https://docs.rs/icu/latest/icu/locale/struct.Locale.html#method.try_from_str Rust documentation for `try_from_str`} for more information. - * @throws {@link FFIError}<{@link LocaleParseError}> - */ - set_region(s: string): void | never; + get ffiValue(): pointer; - /** - * Returns a string representation of {@link Locale `Locale`} script. + static createFromString(name: string): Locale; - * See the {@link https://docs.rs/icu/latest/icu/locale/struct.Locale.html#structfield.id Rust documentation for `id`} for more information. - */ - script(): string | undefined; + static createUnd(): Locale; - /** + clone(): Locale; - * Set the script part of the {@link Locale `Locale`}. Pass an empty string to remove the script. + get basename(): string; - * See the {@link https://docs.rs/icu/latest/icu/locale/struct.Locale.html#method.try_from_str Rust documentation for `try_from_str`} for more information. - * @throws {@link FFIError}<{@link LocaleParseError}> - */ - set_script(s: string): void | never; + getUnicodeExtension(s: string): string | null; - /** + get language(): string; - * Best effort locale canonicalizer that doesn't need any data + set language(s: string); - * Use LocaleCanonicalizer for better control and functionality + get region(): string | null; - * See the {@link https://docs.rs/icu/latest/icu/locale/struct.Locale.html#method.canonicalize Rust documentation for `canonicalize`} for more information. - * @throws {@link FFIError}<{@link LocaleParseError}> - */ - static canonicalize(s: string): string | never; + set region(s: string); - /** + get script(): string | null; - * Returns a string representation of {@link Locale `Locale`}. + set script(s: string); - * See the {@link https://docs.rs/icu/latest/icu/locale/struct.Locale.html#method.write_to Rust documentation for `write_to`} for more information. - */ - to_string(): string; + static canonicalize(s: string): string; - /** + toString(): string; - * See the {@link https://docs.rs/icu/latest/icu/locale/struct.Locale.html#method.normalizing_eq Rust documentation for `normalizing_eq`} for more information. - */ - normalizing_eq(other: string): boolean; + normalizingEq(other: string): boolean; - /** + compareToString(other: string): number; - * See the {@link https://docs.rs/icu/latest/icu/locale/struct.Locale.html#method.strict_cmp Rust documentation for `strict_cmp`} for more information. - */ - strict_cmp(other: string): Ordering; + compareTo(other: Locale): number; - /** + - * See the {@link https://docs.rs/icu/latest/icu/locale/struct.Locale.html#method.total_cmp Rust documentation for `total_cmp`} for more information. - */ - total_cmp(other: Locale): Ordering; -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/Locale.mjs b/ffi/capi/bindings/js/Locale.mjs index 1f70e94ed8e..d2e83a746d8 100644 --- a/ffi/capi/bindings/js/Locale.mjs +++ b/ffi/capi/bindings/js/Locale.mjs @@ -1,195 +1,315 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" -import { LocaleParseError_js_to_rust, LocaleParseError_rust_to_js } from "./LocaleParseError.mjs" -import { Ordering_js_to_rust, Ordering_rust_to_js } from "./Ordering.mjs" +// generated by diplomat-tool +import { LocaleParseError } from "./LocaleParseError.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -const Locale_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XLocale_destroy(underlying); -}); +/** An ICU4X Locale, capable of representing strings like `"en-US"`. +* +*See the [Rust documentation for `Locale`](https://docs.rs/icu/latest/icu/locale/struct.Locale.html) for more information. +*/ + +const Locale_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XLocale_destroy(ptr); +}); export class Locale { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - Locale_box_destroy_registry.register(this, underlying); - } - } - - static create_from_string(arg_name) { - const buf_arg_name = diplomatRuntime.DiplomatBuf.str8(wasm, arg_name); - const diplomat_out = (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XLocale_create_from_string(diplomat_receive_buffer, buf_arg_name.ptr, buf_arg_name.size); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new Locale(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = LocaleParseError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - buf_arg_name.free(); - return diplomat_out; - } - - static create_und() { - return new Locale(wasm.ICU4XLocale_create_und(), true, []); - } - - clone() { - return new Locale(wasm.ICU4XLocale_clone(this.underlying), true, []); - } - - basename() { - return diplomatRuntime.withDiplomatWrite(wasm, (write) => { - return wasm.ICU4XLocale_basename(this.underlying, write); - }); - } - - get_unicode_extension(arg_s) { - const buf_arg_s = diplomatRuntime.DiplomatBuf.str8(wasm, arg_s); - const diplomat_out = diplomatRuntime.withDiplomatWrite(wasm, (write) => { - return (() => { - const is_ok = wasm.ICU4XLocale_get_unicode_extension(this.underlying, buf_arg_s.ptr, buf_arg_s.size, write) == 1; - if (!is_ok) return; - })(); - }); - buf_arg_s.free(); - return diplomat_out; - } - - language() { - return diplomatRuntime.withDiplomatWrite(wasm, (write) => { - return wasm.ICU4XLocale_language(this.underlying, write); - }); - } - - set_language(arg_s) { - const buf_arg_s = diplomatRuntime.DiplomatBuf.str8(wasm, arg_s); - const diplomat_out = (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XLocale_set_language(diplomat_receive_buffer, this.underlying, buf_arg_s.ptr, buf_arg_s.size); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = {}; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = LocaleParseError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - buf_arg_s.free(); - return diplomat_out; - } - - region() { - return diplomatRuntime.withDiplomatWrite(wasm, (write) => { - return (() => { - const is_ok = wasm.ICU4XLocale_region(this.underlying, write) == 1; - if (!is_ok) return; - })(); - }); - } - - set_region(arg_s) { - const buf_arg_s = diplomatRuntime.DiplomatBuf.str8(wasm, arg_s); - const diplomat_out = (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XLocale_set_region(diplomat_receive_buffer, this.underlying, buf_arg_s.ptr, buf_arg_s.size); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = {}; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = LocaleParseError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - buf_arg_s.free(); - return diplomat_out; - } - - script() { - return diplomatRuntime.withDiplomatWrite(wasm, (write) => { - return (() => { - const is_ok = wasm.ICU4XLocale_script(this.underlying, write) == 1; - if (!is_ok) return; - })(); - }); - } - - set_script(arg_s) { - const buf_arg_s = diplomatRuntime.DiplomatBuf.str8(wasm, arg_s); - const diplomat_out = (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XLocale_set_script(diplomat_receive_buffer, this.underlying, buf_arg_s.ptr, buf_arg_s.size); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = {}; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = LocaleParseError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - buf_arg_s.free(); - return diplomat_out; - } - - static canonicalize(arg_s) { - const buf_arg_s = diplomatRuntime.DiplomatBuf.str8(wasm, arg_s); - const diplomat_out = diplomatRuntime.withDiplomatWrite(wasm, (write) => { - return (() => { + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + + constructor(ptr, selfEdge) { + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + Locale_box_destroy_registry.register(this, this.#ptr); + } + + get ffiValue() { + return this.#ptr; + } + + + static createFromString(name) { + + const nameSlice = diplomatRuntime.DiplomatBuf.str8(wasm, name); + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XLocale_create_from_string(diplomat_receive_buffer, nameSlice.ptr, nameSlice.size); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = LocaleParseError[Array.from(LocaleParseError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('LocaleParseError: ' + cause.value, { cause }); + } + return new Locale(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + nameSlice.free(); + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static createUnd() { + const result = wasm.ICU4XLocale_create_und(); + + try { + + return new Locale(result, []); + } finally { + + } + } + + clone() { + const result = wasm.ICU4XLocale_clone(this.ffiValue); + + try { + + return new Locale(result, []); + } finally { + + } + } + + get basename() { + + const write = wasm.diplomat_buffer_write_create(0); + wasm.ICU4XLocale_basename(this.ffiValue, write); + + try { + + return diplomatRuntime.readString8(wasm, wasm.diplomat_buffer_write_get_bytes(write), wasm.diplomat_buffer_write_len(write)); + } finally { + + wasm.diplomat_buffer_write_destroy(write); + + } + } + + getUnicodeExtension(s) { + + const sSlice = diplomatRuntime.DiplomatBuf.str8(wasm, s); + + const write = wasm.diplomat_buffer_write_create(0); + const result = wasm.ICU4XLocale_get_unicode_extension(this.ffiValue, sSlice.ptr, sSlice.size, write); + + try { + + return result == 0 ? null : diplomatRuntime.readString8(wasm, wasm.diplomat_buffer_write_get_bytes(write), wasm.diplomat_buffer_write_len(write)); + } finally { + + sSlice.free(); + + wasm.diplomat_buffer_write_destroy(write); + + } + } + + get language() { + + const write = wasm.diplomat_buffer_write_create(0); + wasm.ICU4XLocale_language(this.ffiValue, write); + + try { + + return diplomatRuntime.readString8(wasm, wasm.diplomat_buffer_write_get_bytes(write), wasm.diplomat_buffer_write_len(write)); + } finally { + + wasm.diplomat_buffer_write_destroy(write); + + } + } + + set language(s) { + + const sSlice = diplomatRuntime.DiplomatBuf.str8(wasm, s); + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XLocale_set_language(diplomat_receive_buffer, this.ffiValue, sSlice.ptr, sSlice.size); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = LocaleParseError[Array.from(LocaleParseError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('LocaleParseError: ' + cause.value, { cause }); + } + + } finally { + + sSlice.free(); + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + get region() { + + const write = wasm.diplomat_buffer_write_create(0); + const result = wasm.ICU4XLocale_region(this.ffiValue, write); + + try { + + return result == 0 ? null : diplomatRuntime.readString8(wasm, wasm.diplomat_buffer_write_get_bytes(write), wasm.diplomat_buffer_write_len(write)); + } finally { + + wasm.diplomat_buffer_write_destroy(write); + + } + } + + set region(s) { + + const sSlice = diplomatRuntime.DiplomatBuf.str8(wasm, s); + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XLocale_set_region(diplomat_receive_buffer, this.ffiValue, sSlice.ptr, sSlice.size); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = LocaleParseError[Array.from(LocaleParseError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('LocaleParseError: ' + cause.value, { cause }); + } + + } finally { + + sSlice.free(); + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + get script() { + + const write = wasm.diplomat_buffer_write_create(0); + const result = wasm.ICU4XLocale_script(this.ffiValue, write); + + try { + + return result == 0 ? null : diplomatRuntime.readString8(wasm, wasm.diplomat_buffer_write_get_bytes(write), wasm.diplomat_buffer_write_len(write)); + } finally { + + wasm.diplomat_buffer_write_destroy(write); + + } + } + + set script(s) { + + const sSlice = diplomatRuntime.DiplomatBuf.str8(wasm, s); + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XLocale_set_script(diplomat_receive_buffer, this.ffiValue, sSlice.ptr, sSlice.size); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = LocaleParseError[Array.from(LocaleParseError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('LocaleParseError: ' + cause.value, { cause }); + } + + } finally { + + sSlice.free(); + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static canonicalize(s) { + + const sSlice = diplomatRuntime.DiplomatBuf.str8(wasm, s); + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XLocale_canonicalize(diplomat_receive_buffer, buf_arg_s.ptr, buf_arg_s.size, write); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = {}; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = LocaleParseError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - }); - buf_arg_s.free(); - return diplomat_out; - } - - to_string() { - return diplomatRuntime.withDiplomatWrite(wasm, (write) => { - return wasm.ICU4XLocale_to_string(this.underlying, write); - }); - } - - normalizing_eq(arg_other) { - const buf_arg_other = diplomatRuntime.DiplomatBuf.str8(wasm, arg_other); - const diplomat_out = wasm.ICU4XLocale_normalizing_eq(this.underlying, buf_arg_other.ptr, buf_arg_other.size); - buf_arg_other.free(); - return diplomat_out; - } - - strict_cmp(arg_other) { - const buf_arg_other = diplomatRuntime.DiplomatBuf.str8(wasm, arg_other); - const diplomat_out = Ordering_rust_to_js[wasm.ICU4XLocale_strict_cmp(this.underlying, buf_arg_other.ptr, buf_arg_other.size)]; - buf_arg_other.free(); - return diplomat_out; - } - - total_cmp(arg_other) { - return Ordering_rust_to_js[wasm.ICU4XLocale_total_cmp(this.underlying, arg_other.underlying)]; - } -} + + const write = wasm.diplomat_buffer_write_create(0); + const result = wasm.ICU4XLocale_canonicalize(diplomat_receive_buffer, sSlice.ptr, sSlice.size, write); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = LocaleParseError[Array.from(LocaleParseError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('LocaleParseError: ' + cause.value, { cause }); + } + return diplomatRuntime.readString8(wasm, wasm.diplomat_buffer_write_get_bytes(write), wasm.diplomat_buffer_write_len(write)); + } finally { + + sSlice.free(); + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + wasm.diplomat_buffer_write_destroy(write); + + } + } + + toString() { + + const write = wasm.diplomat_buffer_write_create(0); + wasm.ICU4XLocale_to_string(this.ffiValue, write); + + try { + + return diplomatRuntime.readString8(wasm, wasm.diplomat_buffer_write_get_bytes(write), wasm.diplomat_buffer_write_len(write)); + } finally { + + wasm.diplomat_buffer_write_destroy(write); + + } + } + + normalizingEq(other) { + + const otherSlice = diplomatRuntime.DiplomatBuf.str8(wasm, other); + const result = wasm.ICU4XLocale_normalizing_eq(this.ffiValue, otherSlice.ptr, otherSlice.size); + + try { + + return result; + } finally { + + otherSlice.free(); + + } + } + + compareToString(other) { + + const otherSlice = diplomatRuntime.DiplomatBuf.str8(wasm, other); + const result = wasm.ICU4XLocale_compare_to_string(this.ffiValue, otherSlice.ptr, otherSlice.size); + + try { + + return result; + } finally { + + otherSlice.free(); + + } + } + + compareTo(other) { + const result = wasm.ICU4XLocale_compare_to(this.ffiValue, other.ffiValue); + + try { + + return result; + } finally { + + } + } + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/LocaleCanonicalizer.d.ts b/ffi/capi/bindings/js/LocaleCanonicalizer.d.ts index 4b1de057243..6d35b2cf9a5 100644 --- a/ffi/capi/bindings/js/LocaleCanonicalizer.d.ts +++ b/ffi/capi/bindings/js/LocaleCanonicalizer.d.ts @@ -1,38 +1,26 @@ -import { FFIError } from "./diplomat-runtime" -import { DataProvider } from "./DataProvider"; -import { Error } from "./Error"; -import { Locale } from "./Locale"; -import { TransformResult } from "./TransformResult"; +// generated by diplomat-tool +import type { DataProvider } from "./DataProvider" +import type { Locale } from "./Locale" +import type { TransformResult } from "./TransformResult" +import type { pointer, char } from "./diplomat-runtime.d.ts"; -/** - * A locale canonicalizer. - - * See the {@link https://docs.rs/icu/latest/icu/locale/struct.LocaleCanonicalizer.html Rust documentation for `LocaleCanonicalizer`} for more information. - */ +/** A locale canonicalizer. +* +*See the [Rust documentation for `LocaleCanonicalizer`](https://docs.rs/icu/latest/icu/locale/struct.LocaleCanonicalizer.html) for more information. +*/ export class LocaleCanonicalizer { + - /** - - * Create a new {@link LocaleCanonicalizer `LocaleCanonicalizer`}. + get ffiValue(): pointer; - * See the {@link https://docs.rs/icu/latest/icu/locale/struct.LocaleCanonicalizer.html#method.new Rust documentation for `new`} for more information. - * @throws {@link FFIError}<{@link Error}> - */ - static create(provider: DataProvider): LocaleCanonicalizer | never; - /** + static create(provider: DataProvider): LocaleCanonicalizer; - * Create a new {@link LocaleCanonicalizer `LocaleCanonicalizer`} with extended data. + static createExtended(provider: DataProvider): LocaleCanonicalizer; - * See the {@link https://docs.rs/icu/latest/icu/locale/struct.LocaleCanonicalizer.html#method.new_with_expander Rust documentation for `new_with_expander`} for more information. - * @throws {@link FFIError}<{@link Error}> - */ - static create_extended(provider: DataProvider): LocaleCanonicalizer | never; + canonicalize(locale: Locale): TransformResult; - /** + - * See the {@link https://docs.rs/icu/latest/icu/locale/struct.LocaleCanonicalizer.html#method.canonicalize Rust documentation for `canonicalize`} for more information. - */ - canonicalize(locale: Locale): TransformResult; -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/LocaleCanonicalizer.mjs b/ffi/capi/bindings/js/LocaleCanonicalizer.mjs index 062dc787962..ea724a92a71 100644 --- a/ffi/capi/bindings/js/LocaleCanonicalizer.mjs +++ b/ffi/capi/bindings/js/LocaleCanonicalizer.mjs @@ -1,57 +1,91 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" -import { Error_js_to_rust, Error_rust_to_js } from "./Error.mjs" -import { TransformResult_js_to_rust, TransformResult_rust_to_js } from "./TransformResult.mjs" +// generated by diplomat-tool +import { DataProvider } from "./DataProvider.mjs" +import { Error } from "./Error.mjs" +import { Locale } from "./Locale.mjs" +import { TransformResult } from "./TransformResult.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -const LocaleCanonicalizer_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XLocaleCanonicalizer_destroy(underlying); -}); +/** A locale canonicalizer. +* +*See the [Rust documentation for `LocaleCanonicalizer`](https://docs.rs/icu/latest/icu/locale/struct.LocaleCanonicalizer.html) for more information. +*/ + +const LocaleCanonicalizer_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XLocaleCanonicalizer_destroy(ptr); +}); export class LocaleCanonicalizer { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - LocaleCanonicalizer_box_destroy_registry.register(this, underlying); + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + + constructor(ptr, selfEdge) { + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + LocaleCanonicalizer_box_destroy_registry.register(this, this.#ptr); } - } - - static create(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XLocaleCanonicalizer_create(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new LocaleCanonicalizer(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = Error_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static create_extended(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XLocaleCanonicalizer_create_extended(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new LocaleCanonicalizer(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = Error_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - canonicalize(arg_locale) { - return TransformResult_rust_to_js[wasm.ICU4XLocaleCanonicalizer_canonicalize(this.underlying, arg_locale.underlying)]; - } -} + + get ffiValue() { + return this.#ptr; + } + + + static create(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XLocaleCanonicalizer_create(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = (() => {for (let i of Error.values) { if(i[1] === diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)) return Error[i[0]]; } return null;})(); + throw new Error('Error: ' + cause.value, { cause }); + } + return new LocaleCanonicalizer(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static createExtended(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XLocaleCanonicalizer_create_extended(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = (() => {for (let i of Error.values) { if(i[1] === diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)) return Error[i[0]]; } return null;})(); + throw new Error('Error: ' + cause.value, { cause }); + } + return new LocaleCanonicalizer(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + canonicalize(locale) { + const result = wasm.ICU4XLocaleCanonicalizer_canonicalize(this.ffiValue, locale.ffiValue); + + try { + + return TransformResult[Array.from(TransformResult.values.keys())[result]]; + } finally { + + } + } + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/LocaleDirection.d.ts b/ffi/capi/bindings/js/LocaleDirection.d.ts index cf12ab7260d..5a9247ecd50 100644 --- a/ffi/capi/bindings/js/LocaleDirection.d.ts +++ b/ffi/capi/bindings/js/LocaleDirection.d.ts @@ -1,16 +1,23 @@ +// generated by diplomat-tool +import type { pointer, char } from "./diplomat-runtime.d.ts"; + +// Base enumerator definition +/** See the [Rust documentation for `Direction`](https://docs.rs/icu/latest/icu/locale/enum.Direction.html) for more information. +*/ +export class LocaleDirection { + constructor(value : LocaleDirection | string); + + get value() : string; + + get ffiValue() : number; + + static LeftToRight : LocaleDirection; + + static RightToLeft : LocaleDirection; + + static Unknown : LocaleDirection; + + + -/** - - * See the {@link https://docs.rs/icu/latest/icu/locale/enum.Direction.html Rust documentation for `Direction`} for more information. - */ -export enum LocaleDirection { - /** - */ - LeftToRight = 'LeftToRight', - /** - */ - RightToLeft = 'RightToLeft', - /** - */ - Unknown = 'Unknown', } \ No newline at end of file diff --git a/ffi/capi/bindings/js/LocaleDirection.mjs b/ffi/capi/bindings/js/LocaleDirection.mjs index 7be55410697..79c244ddace 100644 --- a/ffi/capi/bindings/js/LocaleDirection.mjs +++ b/ffi/capi/bindings/js/LocaleDirection.mjs @@ -1,20 +1,47 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" - -export const LocaleDirection_js_to_rust = { - "LeftToRight": 0, - "RightToLeft": 1, - "Unknown": 2, -}; - -export const LocaleDirection_rust_to_js = { - [0]: "LeftToRight", - [1]: "RightToLeft", - [2]: "Unknown", -}; - -export const LocaleDirection = { - "LeftToRight": "LeftToRight", - "RightToLeft": "RightToLeft", - "Unknown": "Unknown", -}; +// generated by diplomat-tool +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; + +// Base enumerator definition +/** See the [Rust documentation for `Direction`](https://docs.rs/icu/latest/icu/locale/enum.Direction.html) for more information. +*/ +export class LocaleDirection { + #value = undefined; + + static values = new Map([ + ["LeftToRight", 0], + ["RightToLeft", 1], + ["Unknown", 2] + ]); + constructor(value) { + if (value instanceof LocaleDirection) { + this.#value = value.value; + return; + } + + if (LocaleDirection.values.has(value)) { + this.#value = value; + return; + } + + throw TypeError(value + " is not a LocaleDirection and does not correspond to any of its enumerator values."); + } + + get value() { + return this.#value; + } + + get ffiValue() { + return LocaleDirection.values.get(this.#value); + } + + static LeftToRight = new LocaleDirection("LeftToRight"); + + static RightToLeft = new LocaleDirection("RightToLeft"); + + static Unknown = new LocaleDirection("Unknown"); + + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/LocaleDirectionality.d.ts b/ffi/capi/bindings/js/LocaleDirectionality.d.ts index 8e66059f5da..0aeb5e2b135 100644 --- a/ffi/capi/bindings/js/LocaleDirectionality.d.ts +++ b/ffi/capi/bindings/js/LocaleDirectionality.d.ts @@ -1,49 +1,29 @@ -import { FFIError } from "./diplomat-runtime" -import { DataError } from "./DataError"; -import { DataProvider } from "./DataProvider"; -import { Locale } from "./Locale"; -import { LocaleDirection } from "./LocaleDirection"; -import { LocaleExpander } from "./LocaleExpander"; +// generated by diplomat-tool +import type { DataProvider } from "./DataProvider" +import type { Locale } from "./Locale" +import type { LocaleDirection } from "./LocaleDirection" +import type { LocaleExpander } from "./LocaleExpander" +import type { pointer, char } from "./diplomat-runtime.d.ts"; -/** - * See the {@link https://docs.rs/icu/latest/icu/locale/struct.LocaleDirectionality.html Rust documentation for `LocaleDirectionality`} for more information. - */ +/** See the [Rust documentation for `LocaleDirectionality`](https://docs.rs/icu/latest/icu/locale/struct.LocaleDirectionality.html) for more information. +*/ export class LocaleDirectionality { + - /** + get ffiValue(): pointer; - * Construct a new LocaleDirectionality instance - * See the {@link https://docs.rs/icu/latest/icu/locale/struct.LocaleDirectionality.html#method.new Rust documentation for `new`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static create(provider: DataProvider): LocaleDirectionality | never; + static create(provider: DataProvider): LocaleDirectionality; - /** + static createWithExpander(provider: DataProvider, expander: LocaleExpander): LocaleDirectionality; - * Construct a new LocaleDirectionality instance with a custom expander + get(locale: Locale): LocaleDirection; - * See the {@link https://docs.rs/icu/latest/icu/locale/struct.LocaleDirectionality.html#method.new_with_expander Rust documentation for `new_with_expander`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static create_with_expander(provider: DataProvider, expander: LocaleExpander): LocaleDirectionality | never; + isLeftToRight(locale: Locale): boolean; - /** + isRightToLeft(locale: Locale): boolean; - * See the {@link https://docs.rs/icu/latest/icu/locale/struct.LocaleDirectionality.html#method.get Rust documentation for `get`} for more information. - */ - get(locale: Locale): LocaleDirection; + - /** - - * See the {@link https://docs.rs/icu/latest/icu/locale/struct.LocaleDirectionality.html#method.is_left_to_right Rust documentation for `is_left_to_right`} for more information. - */ - is_left_to_right(locale: Locale): boolean; - - /** - - * See the {@link https://docs.rs/icu/latest/icu/locale/struct.LocaleDirectionality.html#method.is_right_to_left Rust documentation for `is_right_to_left`} for more information. - */ - is_right_to_left(locale: Locale): boolean; -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/LocaleDirectionality.mjs b/ffi/capi/bindings/js/LocaleDirectionality.mjs index 7c59c5aa457..9cd8de038dc 100644 --- a/ffi/capi/bindings/js/LocaleDirectionality.mjs +++ b/ffi/capi/bindings/js/LocaleDirectionality.mjs @@ -1,65 +1,112 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" -import { DataError_js_to_rust, DataError_rust_to_js } from "./DataError.mjs" -import { LocaleDirection_js_to_rust, LocaleDirection_rust_to_js } from "./LocaleDirection.mjs" +// generated by diplomat-tool +import { DataError } from "./DataError.mjs" +import { DataProvider } from "./DataProvider.mjs" +import { Locale } from "./Locale.mjs" +import { LocaleDirection } from "./LocaleDirection.mjs" +import { LocaleExpander } from "./LocaleExpander.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -const LocaleDirectionality_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XLocaleDirectionality_destroy(underlying); -}); +/** See the [Rust documentation for `LocaleDirectionality`](https://docs.rs/icu/latest/icu/locale/struct.LocaleDirectionality.html) for more information. +*/ + +const LocaleDirectionality_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XLocaleDirectionality_destroy(ptr); +}); export class LocaleDirectionality { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - LocaleDirectionality_box_destroy_registry.register(this, underlying); + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + + constructor(ptr, selfEdge) { + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + LocaleDirectionality_box_destroy_registry.register(this, this.#ptr); + } + + get ffiValue() { + return this.#ptr; + } + + + static create(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XLocaleDirectionality_create(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new LocaleDirectionality(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } } - } - static create(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XLocaleDirectionality_create(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new LocaleDirectionality(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } + static createWithExpander(provider, expander) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XLocaleDirectionality_create_with_expander(diplomat_receive_buffer, provider.ffiValue, expander.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new LocaleDirectionality(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } - static create_with_expander(arg_provider, arg_expander) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XLocaleDirectionality_create_with_expander(diplomat_receive_buffer, arg_provider.underlying, arg_expander.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new LocaleDirectionality(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } + get(locale) { + const result = wasm.ICU4XLocaleDirectionality_get(this.ffiValue, locale.ffiValue); + + try { + + return LocaleDirection[Array.from(LocaleDirection.values.keys())[result]]; + } finally { + + } + } - get(arg_locale) { - return LocaleDirection_rust_to_js[wasm.ICU4XLocaleDirectionality_get(this.underlying, arg_locale.underlying)]; - } + isLeftToRight(locale) { + const result = wasm.ICU4XLocaleDirectionality_is_left_to_right(this.ffiValue, locale.ffiValue); + + try { + + return result; + } finally { + + } + } + + isRightToLeft(locale) { + const result = wasm.ICU4XLocaleDirectionality_is_right_to_left(this.ffiValue, locale.ffiValue); + + try { + + return result; + } finally { + + } + } - is_left_to_right(arg_locale) { - return wasm.ICU4XLocaleDirectionality_is_left_to_right(this.underlying, arg_locale.underlying); - } + - is_right_to_left(arg_locale) { - return wasm.ICU4XLocaleDirectionality_is_right_to_left(this.underlying, arg_locale.underlying); - } -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/LocaleDisplayNamesFormatter.d.ts b/ffi/capi/bindings/js/LocaleDisplayNamesFormatter.d.ts index 55b80a0953e..90387088635 100644 --- a/ffi/capi/bindings/js/LocaleDisplayNamesFormatter.d.ts +++ b/ffi/capi/bindings/js/LocaleDisplayNamesFormatter.d.ts @@ -1,29 +1,22 @@ -import { FFIError } from "./diplomat-runtime" -import { DataError } from "./DataError"; -import { DataProvider } from "./DataProvider"; -import { DisplayNamesOptionsV1 } from "./DisplayNamesOptionsV1"; -import { Locale } from "./Locale"; +// generated by diplomat-tool +import type { DataProvider } from "./DataProvider" +import type { DisplayNamesOptions } from "./DisplayNamesOptions" +import type { Locale } from "./Locale" +import type { pointer, char } from "./diplomat-runtime.d.ts"; -/** - * See the {@link https://docs.rs/icu/latest/icu/displaynames/struct.LocaleDisplayNamesFormatter.html Rust documentation for `LocaleDisplayNamesFormatter`} for more information. - */ +/** See the [Rust documentation for `LocaleDisplayNamesFormatter`](https://docs.rs/icu/latest/icu/displaynames/struct.LocaleDisplayNamesFormatter.html) for more information. +*/ export class LocaleDisplayNamesFormatter { + - /** + get ffiValue(): pointer; - * Creates a new `LocaleDisplayNamesFormatter` from locale data and an options bag. - * See the {@link https://docs.rs/icu/latest/icu/displaynames/struct.LocaleDisplayNamesFormatter.html#method.try_new Rust documentation for `try_new`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static create(provider: DataProvider, locale: Locale, options: DisplayNamesOptionsV1): LocaleDisplayNamesFormatter | never; + static create(provider: DataProvider, locale: Locale, options: DisplayNamesOptions): LocaleDisplayNamesFormatter; - /** + of(locale: Locale): string; - * Returns the locale-specific display name of a locale. + - * See the {@link https://docs.rs/icu/latest/icu/displaynames/struct.LocaleDisplayNamesFormatter.html#method.of Rust documentation for `of`} for more information. - */ - of(locale: Locale): string; -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/LocaleDisplayNamesFormatter.mjs b/ffi/capi/bindings/js/LocaleDisplayNamesFormatter.mjs index 510b6997ed8..7aef9a67ae9 100644 --- a/ffi/capi/bindings/js/LocaleDisplayNamesFormatter.mjs +++ b/ffi/capi/bindings/js/LocaleDisplayNamesFormatter.mjs @@ -1,47 +1,80 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" -import { DataError_js_to_rust, DataError_rust_to_js } from "./DataError.mjs" -import { DisplayNamesFallback_js_to_rust, DisplayNamesFallback_rust_to_js } from "./DisplayNamesFallback.mjs" -import { DisplayNamesStyle_js_to_rust, DisplayNamesStyle_rust_to_js } from "./DisplayNamesStyle.mjs" -import { LanguageDisplay_js_to_rust, LanguageDisplay_rust_to_js } from "./LanguageDisplay.mjs" - -const LocaleDisplayNamesFormatter_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XLocaleDisplayNamesFormatter_destroy(underlying); -}); +// generated by diplomat-tool +import { DataError } from "./DataError.mjs" +import { DataProvider } from "./DataProvider.mjs" +import { DisplayNamesOptions } from "./DisplayNamesOptions.mjs" +import { Locale } from "./Locale.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; + +/** See the [Rust documentation for `LocaleDisplayNamesFormatter`](https://docs.rs/icu/latest/icu/displaynames/struct.LocaleDisplayNamesFormatter.html) for more information. +*/ + +const LocaleDisplayNamesFormatter_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XLocaleDisplayNamesFormatter_destroy(ptr); +}); export class LocaleDisplayNamesFormatter { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - LocaleDisplayNamesFormatter_box_destroy_registry.register(this, underlying); + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + + constructor(ptr, selfEdge) { + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + LocaleDisplayNamesFormatter_box_destroy_registry.register(this, this.#ptr); + } + + get ffiValue() { + return this.#ptr; } - } - - static create(arg_provider, arg_locale, arg_options) { - const field_style_arg_options = arg_options["style"]; - const field_fallback_arg_options = arg_options["fallback"]; - const field_language_display_arg_options = arg_options["language_display"]; - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XLocaleDisplayNamesFormatter_create(diplomat_receive_buffer, arg_provider.underlying, arg_locale.underlying, DisplayNamesStyle_js_to_rust[field_style_arg_options], DisplayNamesFallback_js_to_rust[field_fallback_arg_options], LanguageDisplay_js_to_rust[field_language_display_arg_options]); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new LocaleDisplayNamesFormatter(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - of(arg_locale) { - return diplomatRuntime.withDiplomatWrite(wasm, (write) => { - return wasm.ICU4XLocaleDisplayNamesFormatter_of(this.underlying, arg_locale.underlying, write); - }); - } -} + + + static create(provider, locale, options) { + + let slice_cleanup_callbacks = []; + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XLocaleDisplayNamesFormatter_create(diplomat_receive_buffer, provider.ffiValue, locale.ffiValue, ...options._intoFFI(slice_cleanup_callbacks, {})); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new LocaleDisplayNamesFormatter(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + for (let cleanup of slice_cleanup_callbacks) { + cleanup(); + } + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + of(locale) { + + const write = wasm.diplomat_buffer_write_create(0); + wasm.ICU4XLocaleDisplayNamesFormatter_of(this.ffiValue, locale.ffiValue, write); + + try { + + return diplomatRuntime.readString8(wasm, wasm.diplomat_buffer_write_get_bytes(write), wasm.diplomat_buffer_write_len(write)); + } finally { + + wasm.diplomat_buffer_write_destroy(write); + + } + } + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/LocaleExpander.d.ts b/ffi/capi/bindings/js/LocaleExpander.d.ts index 3f5ac8d6829..df05e5c6ef0 100644 --- a/ffi/capi/bindings/js/LocaleExpander.d.ts +++ b/ffi/capi/bindings/js/LocaleExpander.d.ts @@ -1,50 +1,30 @@ -import { FFIError } from "./diplomat-runtime" -import { DataProvider } from "./DataProvider"; -import { Error } from "./Error"; -import { Locale } from "./Locale"; -import { TransformResult } from "./TransformResult"; +// generated by diplomat-tool +import type { DataProvider } from "./DataProvider" +import type { Locale } from "./Locale" +import type { TransformResult } from "./TransformResult" +import type { pointer, char } from "./diplomat-runtime.d.ts"; -/** - * A locale expander. - - * See the {@link https://docs.rs/icu/latest/icu/locale/struct.LocaleExpander.html Rust documentation for `LocaleExpander`} for more information. - */ +/** A locale expander. +* +*See the [Rust documentation for `LocaleExpander`](https://docs.rs/icu/latest/icu/locale/struct.LocaleExpander.html) for more information. +*/ export class LocaleExpander { + - /** - - * Create a new {@link LocaleExpander `LocaleExpander`}. - - * See the {@link https://docs.rs/icu/latest/icu/locale/struct.LocaleExpander.html#method.new Rust documentation for `new`} for more information. - * @throws {@link FFIError}<{@link Error}> - */ - static create(provider: DataProvider): LocaleExpander | never; - - /** + get ffiValue(): pointer; - * Create a new {@link LocaleExpander `LocaleExpander`} with extended data. - * See the {@link https://docs.rs/icu/latest/icu/locale/struct.LocaleExpander.html#method.new_extended Rust documentation for `new_extended`} for more information. - * @throws {@link FFIError}<{@link Error}> - */ - static create_extended(provider: DataProvider): LocaleExpander | never; + static create(provider: DataProvider): LocaleExpander; - /** + static createExtended(provider: DataProvider): LocaleExpander; - * See the {@link https://docs.rs/icu/latest/icu/locale/struct.LocaleExpander.html#method.maximize Rust documentation for `maximize`} for more information. - */ - maximize(locale: Locale): TransformResult; + maximize(locale: Locale): TransformResult; - /** + minimize(locale: Locale): TransformResult; - * See the {@link https://docs.rs/icu/latest/icu/locale/struct.LocaleExpander.html#method.minimize Rust documentation for `minimize`} for more information. - */ - minimize(locale: Locale): TransformResult; + minimizeFavorScript(locale: Locale): TransformResult; - /** + - * See the {@link https://docs.rs/icu/latest/icu/locale/struct.LocaleExpander.html#method.minimize_favor_script Rust documentation for `minimize_favor_script`} for more information. - */ - minimize_favor_script(locale: Locale): TransformResult; -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/LocaleExpander.mjs b/ffi/capi/bindings/js/LocaleExpander.mjs index 0e554dd187f..e1bad757bb5 100644 --- a/ffi/capi/bindings/js/LocaleExpander.mjs +++ b/ffi/capi/bindings/js/LocaleExpander.mjs @@ -1,65 +1,113 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" -import { Error_js_to_rust, Error_rust_to_js } from "./Error.mjs" -import { TransformResult_js_to_rust, TransformResult_rust_to_js } from "./TransformResult.mjs" +// generated by diplomat-tool +import { DataProvider } from "./DataProvider.mjs" +import { Error } from "./Error.mjs" +import { Locale } from "./Locale.mjs" +import { TransformResult } from "./TransformResult.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -const LocaleExpander_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XLocaleExpander_destroy(underlying); -}); +/** A locale expander. +* +*See the [Rust documentation for `LocaleExpander`](https://docs.rs/icu/latest/icu/locale/struct.LocaleExpander.html) for more information. +*/ + +const LocaleExpander_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XLocaleExpander_destroy(ptr); +}); export class LocaleExpander { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - LocaleExpander_box_destroy_registry.register(this, underlying); + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + + constructor(ptr, selfEdge) { + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + LocaleExpander_box_destroy_registry.register(this, this.#ptr); + } + + get ffiValue() { + return this.#ptr; + } + + + static create(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XLocaleExpander_create(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = (() => {for (let i of Error.values) { if(i[1] === diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)) return Error[i[0]]; } return null;})(); + throw new Error('Error: ' + cause.value, { cause }); + } + return new LocaleExpander(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } } - } - static create(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XLocaleExpander_create(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new LocaleExpander(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = Error_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } + static createExtended(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XLocaleExpander_create_extended(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = (() => {for (let i of Error.values) { if(i[1] === diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)) return Error[i[0]]; } return null;})(); + throw new Error('Error: ' + cause.value, { cause }); + } + return new LocaleExpander(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } - static create_extended(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XLocaleExpander_create_extended(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new LocaleExpander(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = Error_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } + maximize(locale) { + const result = wasm.ICU4XLocaleExpander_maximize(this.ffiValue, locale.ffiValue); + + try { + + return TransformResult[Array.from(TransformResult.values.keys())[result]]; + } finally { + + } + } - maximize(arg_locale) { - return TransformResult_rust_to_js[wasm.ICU4XLocaleExpander_maximize(this.underlying, arg_locale.underlying)]; - } + minimize(locale) { + const result = wasm.ICU4XLocaleExpander_minimize(this.ffiValue, locale.ffiValue); + + try { + + return TransformResult[Array.from(TransformResult.values.keys())[result]]; + } finally { + + } + } + + minimizeFavorScript(locale) { + const result = wasm.ICU4XLocaleExpander_minimize_favor_script(this.ffiValue, locale.ffiValue); + + try { + + return TransformResult[Array.from(TransformResult.values.keys())[result]]; + } finally { + + } + } - minimize(arg_locale) { - return TransformResult_rust_to_js[wasm.ICU4XLocaleExpander_minimize(this.underlying, arg_locale.underlying)]; - } + - minimize_favor_script(arg_locale) { - return TransformResult_rust_to_js[wasm.ICU4XLocaleExpander_minimize_favor_script(this.underlying, arg_locale.underlying)]; - } -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/LocaleFallbackConfig.d.ts b/ffi/capi/bindings/js/LocaleFallbackConfig.d.ts index 36fd788fb32..5963823c57e 100644 --- a/ffi/capi/bindings/js/LocaleFallbackConfig.d.ts +++ b/ffi/capi/bindings/js/LocaleFallbackConfig.d.ts @@ -1,14 +1,21 @@ -import { LocaleFallbackPriority } from "./LocaleFallbackPriority"; -import { LocaleFallbackSupplement } from "./LocaleFallbackSupplement"; +// generated by diplomat-tool +import type { LocaleFallbackPriority } from "./LocaleFallbackPriority" +import type { LocaleFallbackSupplement } from "./LocaleFallbackSupplement" +import type { pointer, char } from "./diplomat-runtime.d.ts"; -/** - * Collection of configurations for the ICU4X fallback algorithm. - - * See the {@link https://docs.rs/icu/latest/icu/locale/fallback/struct.LocaleFallbackConfig.html Rust documentation for `LocaleFallbackConfig`} for more information. - */ +/** Collection of configurations for the ICU4X fallback algorithm. +* +*See the [Rust documentation for `LocaleFallbackConfig`](https://docs.rs/icu/latest/icu/locale/fallback/struct.LocaleFallbackConfig.html) for more information. +*/ export class LocaleFallbackConfig { - priority: LocaleFallbackPriority; - extension_key: string; - fallback_supplement: LocaleFallbackSupplement; -} + get priority() : LocaleFallbackPriority; + set priority(value: LocaleFallbackPriority); + get extensionKey() : string; + set extensionKey(value: string); + get fallbackSupplement() : LocaleFallbackSupplement; + set fallbackSupplement(value: LocaleFallbackSupplement); + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/LocaleFallbackConfig.mjs b/ffi/capi/bindings/js/LocaleFallbackConfig.mjs index c1e14da9b8b..015b060ec8f 100644 --- a/ffi/capi/bindings/js/LocaleFallbackConfig.mjs +++ b/ffi/capi/bindings/js/LocaleFallbackConfig.mjs @@ -1,15 +1,71 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" -import { LocaleFallbackPriority_js_to_rust, LocaleFallbackPriority_rust_to_js } from "./LocaleFallbackPriority.mjs" -import { LocaleFallbackSupplement_js_to_rust, LocaleFallbackSupplement_rust_to_js } from "./LocaleFallbackSupplement.mjs" +// generated by diplomat-tool +import { LocaleFallbackPriority } from "./LocaleFallbackPriority.mjs" +import { LocaleFallbackSupplement } from "./LocaleFallbackSupplement.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; + +/** Collection of configurations for the ICU4X fallback algorithm. +* +*See the [Rust documentation for `LocaleFallbackConfig`](https://docs.rs/icu/latest/icu/locale/fallback/struct.LocaleFallbackConfig.html) for more information. +*/ export class LocaleFallbackConfig { - constructor(underlying, edges_a) { - this.priority = LocaleFallbackPriority_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, underlying)]; - this.extension_key = (() => { - const [ptr, size] = new Uint32Array(wasm.memory.buffer, underlying + 4, 2); - return diplomatRuntime.readString8(wasm, ptr, size); - })(); - this.fallback_supplement = LocaleFallbackSupplement_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, underlying + 12)]; - } -} + #priority; + get priority() { + return this.#priority; + } + set priority(value) { + this.#priority = value; + } + #extensionKey; + get extensionKey() { + return this.#extensionKey; + } + set extensionKey(value) { + this.#extensionKey = value; + } + #fallbackSupplement; + get fallbackSupplement() { + return this.#fallbackSupplement; + } + set fallbackSupplement(value) { + this.#fallbackSupplement = value; + } + + // Return this struct in FFI function friendly format. + // Returns an array that can be expanded with spread syntax (...) + // If this struct contains any slices, their lifetime-edge-relevant information will be + // set up here, and can be appended to any relevant lifetime arrays here. AppendArray accepts a list + // of arrays for each lifetime to do so. It accepts multiple lists per lifetime in case the caller needs to tie a lifetime to multiple + // output arrays. Null is equivalent to an empty list: this lifetime is not being borrowed from. + _intoFFI( + slice_cleanup_callbacks, + appendArrayMap + ) { + slice_cleanup_callbacks.push((appendArrayMap[aAppendArray] || []).length > 0 ? () => { for (let lifetime of appendArrayMap[aAppendArray]) { appendArrayMap[aAppendArray].push(extensionKey); } extensionKey.garbageCollect(); } : extensionKey.free); + + return [this.#priority.ffiValue, diplomatRuntime.DiplomatBuf.str8(wasm, this.#extensionKey), this.#fallbackSupplement.ffiValue] + } + + _fromFFI(ptr, aEdges) { + const priorityDeref = diplomatRuntime.enumDiscriminant(wasm, ptr); + this.#priority = LocaleFallbackPriority[Array.from(LocaleFallbackPriority.values.keys())[priorityDeref]]; + const extensionKeyDeref = ptr + 4; + this.#extensionKey = diplomatRuntime.DiplomatBuf.stringFromPtr(wasm.memory.buffer, extensionKeyDeref, "string8"); + const fallbackSupplementDeref = diplomatRuntime.enumDiscriminant(wasm, ptr + 12); + this.#fallbackSupplement = LocaleFallbackSupplement[Array.from(LocaleFallbackSupplement.values.keys())[fallbackSupplementDeref]]; + + return this; + } + + // Return all fields corresponding to lifetime `'a` + // without handling lifetime dependencies (this is the job of the caller) + // This is all fields that may be borrowed from if borrowing `'a`, + // assuming that there are no `'other: a`. bounds. In case of such bounds, + // the caller should take care to also call _fieldsForLifetimeOther + get _fieldsForLifetimeA() { + return [extensionKey]; + }; + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/LocaleFallbackIterator.d.ts b/ffi/capi/bindings/js/LocaleFallbackIterator.d.ts index a16af56a283..e5b04f2776a 100644 --- a/ffi/capi/bindings/js/LocaleFallbackIterator.d.ts +++ b/ffi/capi/bindings/js/LocaleFallbackIterator.d.ts @@ -1,26 +1,20 @@ -import { Locale } from "./Locale"; +// generated by diplomat-tool +import type { Locale } from "./Locale" +import type { pointer, char } from "./diplomat-runtime.d.ts"; -/** - * An iterator over the locale under fallback. - - * See the {@link https://docs.rs/icu/latest/icu/locale/fallback/struct.LocaleFallbackIterator.html Rust documentation for `LocaleFallbackIterator`} for more information. - */ +/** An iterator over the locale under fallback. +* +*See the [Rust documentation for `LocaleFallbackIterator`](https://docs.rs/icu/latest/icu/locale/fallback/struct.LocaleFallbackIterator.html) for more information. +*/ export class LocaleFallbackIterator { + - /** - - * Gets a snapshot of the current state of the locale. + get ffiValue(): pointer; - * See the {@link https://docs.rs/icu/latest/icu/locale/fallback/struct.LocaleFallbackIterator.html#method.get Rust documentation for `get`} for more information. - */ - get(): Locale; - /** + next(): Locale | null; - * Performs one step of the fallback algorithm, mutating the locale. + - * See the {@link https://docs.rs/icu/latest/icu/locale/fallback/struct.LocaleFallbackIterator.html#method.step Rust documentation for `step`} for more information. - */ - step(): void; -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/LocaleFallbackIterator.mjs b/ffi/capi/bindings/js/LocaleFallbackIterator.mjs index 356d285a15e..7f58bacd541 100644 --- a/ffi/capi/bindings/js/LocaleFallbackIterator.mjs +++ b/ffi/capi/bindings/js/LocaleFallbackIterator.mjs @@ -1,26 +1,55 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" +// generated by diplomat-tool import { Locale } from "./Locale.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -const LocaleFallbackIterator_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XLocaleFallbackIterator_destroy(underlying); -}); +/** An iterator over the locale under fallback. +* +*See the [Rust documentation for `LocaleFallbackIterator`](https://docs.rs/icu/latest/icu/locale/fallback/struct.LocaleFallbackIterator.html) for more information. +*/ + +const LocaleFallbackIterator_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XLocaleFallbackIterator_destroy(ptr); +}); export class LocaleFallbackIterator { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - LocaleFallbackIterator_box_destroy_registry.register(this, underlying); + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + #aEdge = []; + + + constructor(ptr, selfEdge, aEdge) { + + + this.#aEdge = aEdge; + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + LocaleFallbackIterator_box_destroy_registry.register(this, this.#ptr); + } + + get ffiValue() { + return this.#ptr; + } + + + next() { + const result = wasm.ICU4XLocaleFallbackIterator_next(this.ffiValue); + + try { + + return result == 0 ? null : new Locale(result, []); + } finally { + + } } - } - get() { - return new Locale(wasm.ICU4XLocaleFallbackIterator_get(this.underlying), true, []); - } + - step() { - wasm.ICU4XLocaleFallbackIterator_step(this.underlying); - } -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/LocaleFallbackPriority.d.ts b/ffi/capi/bindings/js/LocaleFallbackPriority.d.ts index 3448be412ba..6e42fd725e7 100644 --- a/ffi/capi/bindings/js/LocaleFallbackPriority.d.ts +++ b/ffi/capi/bindings/js/LocaleFallbackPriority.d.ts @@ -1,18 +1,25 @@ +// generated by diplomat-tool +import type { pointer, char } from "./diplomat-runtime.d.ts"; + +// Base enumerator definition +/** Priority mode for the ICU4X fallback algorithm. +* +*See the [Rust documentation for `LocaleFallbackPriority`](https://docs.rs/icu/latest/icu/locale/fallback/enum.LocaleFallbackPriority.html) for more information. +*/ +export class LocaleFallbackPriority { + constructor(value : LocaleFallbackPriority | string); + + get value() : string; + + get ffiValue() : number; + + static Language : LocaleFallbackPriority; + + static Region : LocaleFallbackPriority; + + static Collation : LocaleFallbackPriority; + + + -/** - - * Priority mode for the ICU4X fallback algorithm. - - * See the {@link https://docs.rs/icu/latest/icu/locale/fallback/enum.LocaleFallbackPriority.html Rust documentation for `LocaleFallbackPriority`} for more information. - */ -export enum LocaleFallbackPriority { - /** - */ - Language = 'Language', - /** - */ - Region = 'Region', - /** - */ - Collation = 'Collation', } \ No newline at end of file diff --git a/ffi/capi/bindings/js/LocaleFallbackPriority.mjs b/ffi/capi/bindings/js/LocaleFallbackPriority.mjs index df939d913b7..c880dff1b63 100644 --- a/ffi/capi/bindings/js/LocaleFallbackPriority.mjs +++ b/ffi/capi/bindings/js/LocaleFallbackPriority.mjs @@ -1,20 +1,49 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" - -export const LocaleFallbackPriority_js_to_rust = { - "Language": 0, - "Region": 1, - "Collation": 2, -}; - -export const LocaleFallbackPriority_rust_to_js = { - [0]: "Language", - [1]: "Region", - [2]: "Collation", -}; - -export const LocaleFallbackPriority = { - "Language": "Language", - "Region": "Region", - "Collation": "Collation", -}; +// generated by diplomat-tool +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; + +// Base enumerator definition +/** Priority mode for the ICU4X fallback algorithm. +* +*See the [Rust documentation for `LocaleFallbackPriority`](https://docs.rs/icu/latest/icu/locale/fallback/enum.LocaleFallbackPriority.html) for more information. +*/ +export class LocaleFallbackPriority { + #value = undefined; + + static values = new Map([ + ["Language", 0], + ["Region", 1], + ["Collation", 2] + ]); + constructor(value) { + if (value instanceof LocaleFallbackPriority) { + this.#value = value.value; + return; + } + + if (LocaleFallbackPriority.values.has(value)) { + this.#value = value; + return; + } + + throw TypeError(value + " is not a LocaleFallbackPriority and does not correspond to any of its enumerator values."); + } + + get value() { + return this.#value; + } + + get ffiValue() { + return LocaleFallbackPriority.values.get(this.#value); + } + + static Language = new LocaleFallbackPriority("Language"); + + static Region = new LocaleFallbackPriority("Region"); + + static Collation = new LocaleFallbackPriority("Collation"); + + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/LocaleFallbackSupplement.d.ts b/ffi/capi/bindings/js/LocaleFallbackSupplement.d.ts index 83523ddbe76..8c7138dffb8 100644 --- a/ffi/capi/bindings/js/LocaleFallbackSupplement.d.ts +++ b/ffi/capi/bindings/js/LocaleFallbackSupplement.d.ts @@ -1,15 +1,23 @@ +// generated by diplomat-tool +import type { pointer, char } from "./diplomat-runtime.d.ts"; -/** +// Base enumerator definition +/** What additional data is required to load when performing fallback. +* +*See the [Rust documentation for `LocaleFallbackSupplement`](https://docs.rs/icu/latest/icu/locale/fallback/enum.LocaleFallbackSupplement.html) for more information. +*/ +export class LocaleFallbackSupplement { + constructor(value : LocaleFallbackSupplement | string); - * What additional data is required to load when performing fallback. + get value() : string; + + get ffiValue() : number; + + static None : LocaleFallbackSupplement; + + static Collation : LocaleFallbackSupplement; + + + - * See the {@link https://docs.rs/icu/latest/icu/locale/fallback/enum.LocaleFallbackSupplement.html Rust documentation for `LocaleFallbackSupplement`} for more information. - */ -export enum LocaleFallbackSupplement { - /** - */ - None = 'None', - /** - */ - Collation = 'Collation', } \ No newline at end of file diff --git a/ffi/capi/bindings/js/LocaleFallbackSupplement.mjs b/ffi/capi/bindings/js/LocaleFallbackSupplement.mjs index ecc8956dbfa..da09b7676ac 100644 --- a/ffi/capi/bindings/js/LocaleFallbackSupplement.mjs +++ b/ffi/capi/bindings/js/LocaleFallbackSupplement.mjs @@ -1,17 +1,46 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" - -export const LocaleFallbackSupplement_js_to_rust = { - "None": 0, - "Collation": 1, -}; - -export const LocaleFallbackSupplement_rust_to_js = { - [0]: "None", - [1]: "Collation", -}; - -export const LocaleFallbackSupplement = { - "None": "None", - "Collation": "Collation", -}; +// generated by diplomat-tool +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; + +// Base enumerator definition +/** What additional data is required to load when performing fallback. +* +*See the [Rust documentation for `LocaleFallbackSupplement`](https://docs.rs/icu/latest/icu/locale/fallback/enum.LocaleFallbackSupplement.html) for more information. +*/ +export class LocaleFallbackSupplement { + #value = undefined; + + static values = new Map([ + ["None", 0], + ["Collation", 1] + ]); + constructor(value) { + if (value instanceof LocaleFallbackSupplement) { + this.#value = value.value; + return; + } + + if (LocaleFallbackSupplement.values.has(value)) { + this.#value = value; + return; + } + + throw TypeError(value + " is not a LocaleFallbackSupplement and does not correspond to any of its enumerator values."); + } + + get value() { + return this.#value; + } + + get ffiValue() { + return LocaleFallbackSupplement.values.get(this.#value); + } + + static None = new LocaleFallbackSupplement("None"); + + static Collation = new LocaleFallbackSupplement("Collation"); + + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/LocaleFallbacker.d.ts b/ffi/capi/bindings/js/LocaleFallbacker.d.ts index 246d78fe107..e227cc08553 100644 --- a/ffi/capi/bindings/js/LocaleFallbacker.d.ts +++ b/ffi/capi/bindings/js/LocaleFallbacker.d.ts @@ -1,41 +1,26 @@ -import { FFIError } from "./diplomat-runtime" -import { DataError } from "./DataError"; -import { DataProvider } from "./DataProvider"; -import { LocaleFallbackConfig } from "./LocaleFallbackConfig"; -import { LocaleFallbackerWithConfig } from "./LocaleFallbackerWithConfig"; -import { LocaleParseError } from "./LocaleParseError"; +// generated by diplomat-tool +import type { DataProvider } from "./DataProvider" +import type { LocaleFallbackConfig } from "./LocaleFallbackConfig" +import type { LocaleFallbackerWithConfig } from "./LocaleFallbackerWithConfig" +import type { pointer, char } from "./diplomat-runtime.d.ts"; -/** - * An object that runs the ICU4X locale fallback algorithm. - - * See the {@link https://docs.rs/icu/latest/icu/locale/fallback/struct.LocaleFallbacker.html Rust documentation for `LocaleFallbacker`} for more information. - */ +/** An object that runs the ICU4X locale fallback algorithm. +* +*See the [Rust documentation for `LocaleFallbacker`](https://docs.rs/icu/latest/icu/locale/fallback/struct.LocaleFallbacker.html) for more information. +*/ export class LocaleFallbacker { + - /** - - * Creates a new `LocaleFallbacker` from a data provider. - - * See the {@link https://docs.rs/icu/latest/icu/locale/fallback/struct.LocaleFallbacker.html#method.new Rust documentation for `new`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static create(provider: DataProvider): LocaleFallbacker | never; + get ffiValue(): pointer; - /** - * Creates a new `LocaleFallbacker` without data for limited functionality. + static create(provider: DataProvider): LocaleFallbacker; - * See the {@link https://docs.rs/icu/latest/icu/locale/fallback/struct.LocaleFallbacker.html#method.new_without_data Rust documentation for `new_without_data`} for more information. - */ - static create_without_data(): LocaleFallbacker; + static createWithoutData(): LocaleFallbacker; - /** + forConfig(config: LocaleFallbackConfig): LocaleFallbackerWithConfig; - * Associates this `LocaleFallbacker` with configuration options. + - * See the {@link https://docs.rs/icu/latest/icu/locale/fallback/struct.LocaleFallbacker.html#method.for_config Rust documentation for `for_config`} for more information. - * @throws {@link FFIError}<{@link LocaleParseError}> - */ - for_config(config: LocaleFallbackConfig): LocaleFallbackerWithConfig | never; -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/LocaleFallbacker.mjs b/ffi/capi/bindings/js/LocaleFallbacker.mjs index c4ad236451d..a410e554c80 100644 --- a/ffi/capi/bindings/js/LocaleFallbacker.mjs +++ b/ffi/capi/bindings/js/LocaleFallbacker.mjs @@ -1,66 +1,101 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" -import { DataError_js_to_rust, DataError_rust_to_js } from "./DataError.mjs" -import { LocaleFallbackPriority_js_to_rust, LocaleFallbackPriority_rust_to_js } from "./LocaleFallbackPriority.mjs" -import { LocaleFallbackSupplement_js_to_rust, LocaleFallbackSupplement_rust_to_js } from "./LocaleFallbackSupplement.mjs" +// generated by diplomat-tool +import { DataError } from "./DataError.mjs" +import { DataProvider } from "./DataProvider.mjs" +import { LocaleFallbackConfig } from "./LocaleFallbackConfig.mjs" import { LocaleFallbackerWithConfig } from "./LocaleFallbackerWithConfig.mjs" -import { LocaleParseError_js_to_rust, LocaleParseError_rust_to_js } from "./LocaleParseError.mjs" +import { LocaleParseError } from "./LocaleParseError.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -const LocaleFallbacker_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XLocaleFallbacker_destroy(underlying); -}); +/** An object that runs the ICU4X locale fallback algorithm. +* +*See the [Rust documentation for `LocaleFallbacker`](https://docs.rs/icu/latest/icu/locale/fallback/struct.LocaleFallbacker.html) for more information. +*/ + +const LocaleFallbacker_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XLocaleFallbacker_destroy(ptr); +}); export class LocaleFallbacker { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - LocaleFallbacker_box_destroy_registry.register(this, underlying); + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + + constructor(ptr, selfEdge) { + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + LocaleFallbacker_box_destroy_registry.register(this, this.#ptr); + } + + get ffiValue() { + return this.#ptr; } - } - static create(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XLocaleFallbacker_create(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new LocaleFallbacker(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - static create_without_data() { - return new LocaleFallbacker(wasm.ICU4XLocaleFallbacker_create_without_data(), true, []); - } + static create(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XLocaleFallbacker_create(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new LocaleFallbacker(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static createWithoutData() { + const result = wasm.ICU4XLocaleFallbacker_create_without_data(); + + try { + + return new LocaleFallbacker(result, []); + } finally { + + } + } + + forConfig(config) { + + let slice_cleanup_callbacks = []; + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + + // This lifetime edge depends on lifetimes 'a + let aEdges = [this]; + const result = wasm.ICU4XLocaleFallbacker_for_config(diplomat_receive_buffer, this.ffiValue, ...config._intoFFI(slice_cleanup_callbacks, {})); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = LocaleParseError[Array.from(LocaleParseError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('LocaleParseError: ' + cause.value, { cause }); + } + return new LocaleFallbackerWithConfig(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), [], aEdges); + } finally { + + for (let cleanup of slice_cleanup_callbacks) { + cleanup(); + } + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + - for_config(arg_config) { - const field_priority_arg_config = arg_config["priority"]; - const field_extension_key_arg_config = arg_config["extension_key"]; - const buf_field_extension_key_arg_config = diplomatRuntime.DiplomatBuf.str8(wasm, field_extension_key_arg_config); - const field_fallback_supplement_arg_config = arg_config["fallback_supplement"]; - const diplomat_out = (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XLocaleFallbacker_for_config(diplomat_receive_buffer, this.underlying, LocaleFallbackPriority_js_to_rust[field_priority_arg_config], buf_field_extension_key_arg_config.ptr, buf_field_extension_key_arg_config.size, LocaleFallbackSupplement_js_to_rust[field_fallback_supplement_arg_config]); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new LocaleFallbackerWithConfig(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, [this]); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = LocaleParseError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - buf_field_extension_key_arg_config.free(); - return diplomat_out; - } -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/LocaleFallbackerWithConfig.d.ts b/ffi/capi/bindings/js/LocaleFallbackerWithConfig.d.ts index d5e1cf62377..1cf53e4f3e4 100644 --- a/ffi/capi/bindings/js/LocaleFallbackerWithConfig.d.ts +++ b/ffi/capi/bindings/js/LocaleFallbackerWithConfig.d.ts @@ -1,21 +1,23 @@ -import { Locale } from "./Locale"; -import { LocaleFallbackIterator } from "./LocaleFallbackIterator"; +// generated by diplomat-tool +import type { Locale } from "./Locale" +import type { LocaleFallbackIterator } from "./LocaleFallbackIterator" +import type { pointer, char } from "./diplomat-runtime.d.ts"; -/** - * An object that runs the ICU4X locale fallback algorithm with specific configurations. +/** An object that runs the ICU4X locale fallback algorithm with specific configurations. +* +*See the [Rust documentation for `LocaleFallbacker`](https://docs.rs/icu/latest/icu/locale/fallback/struct.LocaleFallbacker.html) for more information. +* +*See the [Rust documentation for `LocaleFallbackerWithConfig`](https://docs.rs/icu/latest/icu/locale/fallback/struct.LocaleFallbackerWithConfig.html) for more information. +*/ +export class LocaleFallbackerWithConfig { + - * See the {@link https://docs.rs/icu/latest/icu/locale/fallback/struct.LocaleFallbacker.html Rust documentation for `LocaleFallbacker`} for more information. + get ffiValue(): pointer; - * See the {@link https://docs.rs/icu/latest/icu/locale/fallback/struct.LocaleFallbackerWithConfig.html Rust documentation for `LocaleFallbackerWithConfig`} for more information. - */ -export class LocaleFallbackerWithConfig { - /** + fallbackForLocale(locale: Locale): LocaleFallbackIterator; - * Creates an iterator from a locale with each step of fallback. + - * See the {@link https://docs.rs/icu/latest/icu/locale/fallback/struct.LocaleFallbacker.html#method.fallback_for Rust documentation for `fallback_for`} for more information. - */ - fallback_for_locale(locale: Locale): LocaleFallbackIterator; -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/LocaleFallbackerWithConfig.mjs b/ffi/capi/bindings/js/LocaleFallbackerWithConfig.mjs index c67af95f32f..3d48f72ae2f 100644 --- a/ffi/capi/bindings/js/LocaleFallbackerWithConfig.mjs +++ b/ffi/capi/bindings/js/LocaleFallbackerWithConfig.mjs @@ -1,22 +1,61 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" +// generated by diplomat-tool +import { Locale } from "./Locale.mjs" import { LocaleFallbackIterator } from "./LocaleFallbackIterator.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -const LocaleFallbackerWithConfig_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XLocaleFallbackerWithConfig_destroy(underlying); -}); +/** An object that runs the ICU4X locale fallback algorithm with specific configurations. +* +*See the [Rust documentation for `LocaleFallbacker`](https://docs.rs/icu/latest/icu/locale/fallback/struct.LocaleFallbacker.html) for more information. +* +*See the [Rust documentation for `LocaleFallbackerWithConfig`](https://docs.rs/icu/latest/icu/locale/fallback/struct.LocaleFallbackerWithConfig.html) for more information. +*/ + +const LocaleFallbackerWithConfig_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XLocaleFallbackerWithConfig_destroy(ptr); +}); export class LocaleFallbackerWithConfig { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - LocaleFallbackerWithConfig_box_destroy_registry.register(this, underlying); + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + #aEdge = []; + + + constructor(ptr, selfEdge, aEdge) { + + + this.#aEdge = aEdge; + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + LocaleFallbackerWithConfig_box_destroy_registry.register(this, this.#ptr); + } + + get ffiValue() { + return this.#ptr; } - } - fallback_for_locale(arg_locale) { - return new LocaleFallbackIterator(wasm.ICU4XLocaleFallbackerWithConfig_fallback_for_locale(this.underlying, arg_locale.underlying), true, [this]); - } -} + + fallbackForLocale(locale) { + + // This lifetime edge depends on lifetimes 'a, 'b + let aEdges = [this]; + const result = wasm.ICU4XLocaleFallbackerWithConfig_fallback_for_locale(this.ffiValue, locale.ffiValue); + + try { + + return new LocaleFallbackIterator(result, [], aEdges); + } finally { + + } + } + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/LocaleParseError.d.ts b/ffi/capi/bindings/js/LocaleParseError.d.ts index 54d472e1c6b..46afdce724c 100644 --- a/ffi/capi/bindings/js/LocaleParseError.d.ts +++ b/ffi/capi/bindings/js/LocaleParseError.d.ts @@ -1,19 +1,25 @@ +// generated by diplomat-tool +import type { pointer, char } from "./diplomat-runtime.d.ts"; + +// Base enumerator definition +/** Additional information: [1](https://docs.rs/icu/latest/icu/locale/enum.ParseError.html) +*/ +export class LocaleParseError { + constructor(value : LocaleParseError | string); + + get value() : string; + + get ffiValue() : number; + + static Unknown : LocaleParseError; + + static Language : LocaleParseError; + + static Subtag : LocaleParseError; + + static Extension : LocaleParseError; + + + -/** - - * Additional information: {@link https://docs.rs/icu/latest/icu/locale/enum.ParseError.html 1} - */ -export enum LocaleParseError { - /** - */ - Unknown = 'Unknown', - /** - */ - Language = 'Language', - /** - */ - Subtag = 'Subtag', - /** - */ - Extension = 'Extension', } \ No newline at end of file diff --git a/ffi/capi/bindings/js/LocaleParseError.mjs b/ffi/capi/bindings/js/LocaleParseError.mjs index 04ef827b570..ae96c1289ef 100644 --- a/ffi/capi/bindings/js/LocaleParseError.mjs +++ b/ffi/capi/bindings/js/LocaleParseError.mjs @@ -1,23 +1,50 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" - -export const LocaleParseError_js_to_rust = { - "Unknown": 0, - "Language": 1, - "Subtag": 2, - "Extension": 3, -}; - -export const LocaleParseError_rust_to_js = { - [0]: "Unknown", - [1]: "Language", - [2]: "Subtag", - [3]: "Extension", -}; - -export const LocaleParseError = { - "Unknown": "Unknown", - "Language": "Language", - "Subtag": "Subtag", - "Extension": "Extension", -}; +// generated by diplomat-tool +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; + +// Base enumerator definition +/** Additional information: [1](https://docs.rs/icu/latest/icu/locale/enum.ParseError.html) +*/ +export class LocaleParseError { + #value = undefined; + + static values = new Map([ + ["Unknown", 0], + ["Language", 1], + ["Subtag", 2], + ["Extension", 3] + ]); + constructor(value) { + if (value instanceof LocaleParseError) { + this.#value = value.value; + return; + } + + if (LocaleParseError.values.has(value)) { + this.#value = value; + return; + } + + throw TypeError(value + " is not a LocaleParseError and does not correspond to any of its enumerator values."); + } + + get value() { + return this.#value; + } + + get ffiValue() { + return LocaleParseError.values.get(this.#value); + } + + static Unknown = new LocaleParseError("Unknown"); + + static Language = new LocaleParseError("Language"); + + static Subtag = new LocaleParseError("Subtag"); + + static Extension = new LocaleParseError("Extension"); + + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/Logger.d.ts b/ffi/capi/bindings/js/Logger.d.ts index 47c6197749c..e91c9793db4 100644 --- a/ffi/capi/bindings/js/Logger.d.ts +++ b/ffi/capi/bindings/js/Logger.d.ts @@ -1,17 +1,17 @@ +// generated by diplomat-tool +import type { pointer, char } from "./diplomat-runtime.d.ts"; -/** - * An object allowing control over the logging used - */ +/** An object allowing control over the logging used +*/ export class Logger { + - /** + get ffiValue(): pointer; - * Initialize the logger using `simple_logger` - * Requires the `simple_logger` Cargo feature. + static initSimpleLogger(): boolean; - * Returns `false` if there was already a logger set. - */ - static init_simple_logger(): boolean; -} + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/Logger.mjs b/ffi/capi/bindings/js/Logger.mjs index f733ad76540..df374d58274 100644 --- a/ffi/capi/bindings/js/Logger.mjs +++ b/ffi/capi/bindings/js/Logger.mjs @@ -1,21 +1,47 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" +// generated by diplomat-tool +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -const Logger_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XLogger_destroy(underlying); -}); +/** An object allowing control over the logging used +*/ + +const Logger_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XLogger_destroy(ptr); +}); export class Logger { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - Logger_box_destroy_registry.register(this, underlying); + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + + constructor(ptr, selfEdge) { + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + Logger_box_destroy_registry.register(this, this.#ptr); + } + + get ffiValue() { + return this.#ptr; } - } - static init_simple_logger() { - return wasm.ICU4XLogger_init_simple_logger(); - } -} + + static initSimpleLogger() { + const result = wasm.ICU4XLogger_init_simple_logger(); + + try { + + return result; + } finally { + + } + } + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/MeasureUnit.d.ts b/ffi/capi/bindings/js/MeasureUnit.d.ts index 8176f2a9cca..432cdd1503e 100644 --- a/ffi/capi/bindings/js/MeasureUnit.d.ts +++ b/ffi/capi/bindings/js/MeasureUnit.d.ts @@ -1,11 +1,20 @@ +// generated by diplomat-tool +import type { pointer, char } from "./diplomat-runtime.d.ts"; -/** - * An ICU4X Measurement Unit object which represents a single unit of measurement such as `meter`, `second`, `kilometer-per-hour`, `square-meter`, etc. +/** An ICU4X Measurement Unit object which represents a single unit of measurement +*such as `meter`, `second`, `kilometer-per-hour`, `square-meter`, etc. +* +*You can create an instance of this object using [`MeasureUnitParser`] by calling the `parse_measure_unit` method. +* +*See the [Rust documentation for `MeasureUnit`](https://docs.rs/icu/latest/icu/experimental/units/measureunit/struct.MeasureUnit.html) for more information. +*/ +export class MeasureUnit { + - * You can create an instance of this object using {@link MeasureUnitParser `MeasureUnitParser`} by calling the `parse_measure_unit` method. + get ffiValue(): pointer; - * See the {@link https://docs.rs/icu/latest/icu/experimental/units/measureunit/struct.MeasureUnit.html Rust documentation for `MeasureUnit`} for more information. - */ -export class MeasureUnit { -} + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/MeasureUnit.mjs b/ffi/capi/bindings/js/MeasureUnit.mjs index 8bb9abc3d99..94288020df0 100644 --- a/ffi/capi/bindings/js/MeasureUnit.mjs +++ b/ffi/capi/bindings/js/MeasureUnit.mjs @@ -1,17 +1,41 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" +// generated by diplomat-tool +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -const MeasureUnit_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XMeasureUnit_destroy(underlying); -}); +/** An ICU4X Measurement Unit object which represents a single unit of measurement +*such as `meter`, `second`, `kilometer-per-hour`, `square-meter`, etc. +* +*You can create an instance of this object using [`MeasureUnitParser`] by calling the `parse_measure_unit` method. +* +*See the [Rust documentation for `MeasureUnit`](https://docs.rs/icu/latest/icu/experimental/units/measureunit/struct.MeasureUnit.html) for more information. +*/ + +const MeasureUnit_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XMeasureUnit_destroy(ptr); +}); export class MeasureUnit { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - MeasureUnit_box_destroy_registry.register(this, underlying); + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + + constructor(ptr, selfEdge) { + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + MeasureUnit_box_destroy_registry.register(this, this.#ptr); } - } -} + + get ffiValue() { + return this.#ptr; + } + + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/MeasureUnitParser.d.ts b/ffi/capi/bindings/js/MeasureUnitParser.d.ts index 4a46e3a8b95..a8e26fc9c2c 100644 --- a/ffi/capi/bindings/js/MeasureUnitParser.d.ts +++ b/ffi/capi/bindings/js/MeasureUnitParser.d.ts @@ -1,18 +1,21 @@ -import { MeasureUnit } from "./MeasureUnit"; +// generated by diplomat-tool +import type { MeasureUnit } from "./MeasureUnit" +import type { pointer, char } from "./diplomat-runtime.d.ts"; -/** - * An ICU4X Measurement Unit parser object which is capable of parsing the CLDR unit identifier (e.g. `meter-per-square-second`) and get the {@link MeasureUnit `MeasureUnit`}. - - * See the {@link https://docs.rs/icu/latest/icu/experimental/units/measureunit/struct.MeasureUnitParser.html Rust documentation for `MeasureUnitParser`} for more information. - */ +/** An ICU4X Measurement Unit parser object which is capable of parsing the CLDR unit identifier +*(e.g. `meter-per-square-second`) and get the [`MeasureUnit`]. +* +*See the [Rust documentation for `MeasureUnitParser`](https://docs.rs/icu/latest/icu/experimental/units/measureunit/struct.MeasureUnitParser.html) for more information. +*/ export class MeasureUnitParser { + + + get ffiValue(): pointer; + - /** + parse(unitId: string): MeasureUnit | null; - * Parses the CLDR unit identifier (e.g. `meter-per-square-second`) and returns the corresponding {@link MeasureUnit `MeasureUnit`}, if the identifier is valid. + - * See the {@link https://docs.rs/icu/latest/icu/experimental/units/measureunit/struct.MeasureUnitParser.html#method.parse Rust documentation for `parse`} for more information. - */ - parse(unit_id: string): MeasureUnit | undefined; -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/MeasureUnitParser.mjs b/ffi/capi/bindings/js/MeasureUnitParser.mjs index 055f41404a4..17419630cb9 100644 --- a/ffi/capi/bindings/js/MeasureUnitParser.mjs +++ b/ffi/capi/bindings/js/MeasureUnitParser.mjs @@ -1,28 +1,60 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" +// generated by diplomat-tool import { MeasureUnit } from "./MeasureUnit.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -const MeasureUnitParser_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XMeasureUnitParser_destroy(underlying); -}); +/** An ICU4X Measurement Unit parser object which is capable of parsing the CLDR unit identifier +*(e.g. `meter-per-square-second`) and get the [`MeasureUnit`]. +* +*See the [Rust documentation for `MeasureUnitParser`](https://docs.rs/icu/latest/icu/experimental/units/measureunit/struct.MeasureUnitParser.html) for more information. +*/ + +const MeasureUnitParser_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XMeasureUnitParser_destroy(ptr); +}); export class MeasureUnitParser { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - MeasureUnitParser_box_destroy_registry.register(this, underlying); + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + #aEdge = []; + + + constructor(ptr, selfEdge, aEdge) { + + + this.#aEdge = aEdge; + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + MeasureUnitParser_box_destroy_registry.register(this, this.#ptr); + } + + get ffiValue() { + return this.#ptr; } - } - - parse(arg_unit_id) { - const buf_arg_unit_id = diplomatRuntime.DiplomatBuf.str8(wasm, arg_unit_id); - const diplomat_out = (() => { - const option_ptr = wasm.ICU4XMeasureUnitParser_parse(this.underlying, buf_arg_unit_id.ptr, buf_arg_unit_id.size); - return (option_ptr == 0) ? undefined : new MeasureUnit(option_ptr, true, []); - })(); - buf_arg_unit_id.free(); - return diplomat_out; - } -} + + + parse(unitId) { + + const unitIdSlice = diplomatRuntime.DiplomatBuf.str8(wasm, unitId); + const result = wasm.ICU4XMeasureUnitParser_parse(this.ffiValue, unitIdSlice.ptr, unitIdSlice.size); + + try { + + return result == 0 ? null : new MeasureUnit(result, []); + } finally { + + unitIdSlice.free(); + + } + } + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/MetazoneCalculator.d.ts b/ffi/capi/bindings/js/MetazoneCalculator.d.ts index 417d16f0056..f1d439efa85 100644 --- a/ffi/capi/bindings/js/MetazoneCalculator.d.ts +++ b/ffi/capi/bindings/js/MetazoneCalculator.d.ts @@ -1,21 +1,24 @@ -import { FFIError } from "./diplomat-runtime" -import { DataError } from "./DataError"; -import { DataProvider } from "./DataProvider"; +// generated by diplomat-tool +import type { DataProvider } from "./DataProvider" +import type { pointer, char } from "./diplomat-runtime.d.ts"; -/** - * An object capable of computing the metazone from a timezone. +/** An object capable of computing the metazone from a timezone. +* +*This can be used via `maybe_calculate_metazone()` on [`CustomTimeZone`]. +* +*[`CustomTimeZone`]: crate::timezone::ffi::CustomTimeZone +* +*See the [Rust documentation for `MetazoneCalculator`](https://docs.rs/icu/latest/icu/timezone/struct.MetazoneCalculator.html) for more information. +*/ +export class MetazoneCalculator { + - * This can be used via `maybe_calculate_metazone()` on {@link crate::timezone::ffi::CustomTimeZone `CustomTimeZone`}. + get ffiValue(): pointer; - * See the {@link https://docs.rs/icu/latest/icu/timezone/struct.MetazoneCalculator.html Rust documentation for `MetazoneCalculator`} for more information. - */ -export class MetazoneCalculator { - /** + static create(provider: DataProvider): MetazoneCalculator; + + - * See the {@link https://docs.rs/icu/latest/icu/timezone/struct.MetazoneCalculator.html#method.new Rust documentation for `new`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static create(provider: DataProvider): MetazoneCalculator | never; -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/MetazoneCalculator.mjs b/ffi/capi/bindings/js/MetazoneCalculator.mjs index 227627bd0ce..6a15f354513 100644 --- a/ffi/capi/bindings/js/MetazoneCalculator.mjs +++ b/ffi/capi/bindings/js/MetazoneCalculator.mjs @@ -1,35 +1,63 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" -import { DataError_js_to_rust, DataError_rust_to_js } from "./DataError.mjs" +// generated by diplomat-tool +import { DataError } from "./DataError.mjs" +import { DataProvider } from "./DataProvider.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -const MetazoneCalculator_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XMetazoneCalculator_destroy(underlying); -}); +/** An object capable of computing the metazone from a timezone. +* +*This can be used via `maybe_calculate_metazone()` on [`CustomTimeZone`]. +* +*[`CustomTimeZone`]: crate::timezone::ffi::CustomTimeZone +* +*See the [Rust documentation for `MetazoneCalculator`](https://docs.rs/icu/latest/icu/timezone/struct.MetazoneCalculator.html) for more information. +*/ + +const MetazoneCalculator_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XMetazoneCalculator_destroy(ptr); +}); export class MetazoneCalculator { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - MetazoneCalculator_box_destroy_registry.register(this, underlying); + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + + constructor(ptr, selfEdge) { + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + MetazoneCalculator_box_destroy_registry.register(this, this.#ptr); + } + + get ffiValue() { + return this.#ptr; } - } - - static create(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XMetazoneCalculator_create(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new MetazoneCalculator(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } -} + + + static create(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XMetazoneCalculator_create(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new MetazoneCalculator(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/Ordering.d.ts b/ffi/capi/bindings/js/Ordering.d.ts deleted file mode 100644 index 0b70d4f956e..00000000000 --- a/ffi/capi/bindings/js/Ordering.d.ts +++ /dev/null @@ -1,16 +0,0 @@ - -/** - - * See the {@link https://docs.rs/core/latest/core/cmp/enum.Ordering.html Rust documentation for `Ordering`} for more information. - */ -export enum Ordering { - /** - */ - Less = 'Less', - /** - */ - Equal = 'Equal', - /** - */ - Greater = 'Greater', -} \ No newline at end of file diff --git a/ffi/capi/bindings/js/Ordering.mjs b/ffi/capi/bindings/js/Ordering.mjs deleted file mode 100644 index 1c5ebfcf829..00000000000 --- a/ffi/capi/bindings/js/Ordering.mjs +++ /dev/null @@ -1,20 +0,0 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" - -export const Ordering_js_to_rust = { - "Less": -1, - "Equal": 0, - "Greater": 1, -}; - -export const Ordering_rust_to_js = { - [-1]: "Less", - [0]: "Equal", - [1]: "Greater", -}; - -export const Ordering = { - "Less": "Less", - "Equal": "Equal", - "Greater": "Greater", -}; diff --git a/ffi/capi/bindings/js/PluralCategories.d.ts b/ffi/capi/bindings/js/PluralCategories.d.ts index ae88e02d9a5..44915ad3e74 100644 --- a/ffi/capi/bindings/js/PluralCategories.d.ts +++ b/ffi/capi/bindings/js/PluralCategories.d.ts @@ -1,11 +1,20 @@ +// generated by diplomat-tool +import type { pointer, char } from "./diplomat-runtime.d.ts"; -/** - */ export class PluralCategories { - zero: boolean; - one: boolean; - two: boolean; - few: boolean; - many: boolean; - other: boolean; -} + get zero() : boolean; + + get one() : boolean; + + get two() : boolean; + + get few() : boolean; + + get many() : boolean; + + get other() : boolean; + + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/PluralCategories.mjs b/ffi/capi/bindings/js/PluralCategories.mjs index 5f0652e6c0e..86849d8ec40 100644 --- a/ffi/capi/bindings/js/PluralCategories.mjs +++ b/ffi/capi/bindings/js/PluralCategories.mjs @@ -1,13 +1,74 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" +// generated by diplomat-tool +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; export class PluralCategories { - constructor(underlying) { - this.zero = (new Uint8Array(wasm.memory.buffer, underlying, 1))[0] == 1; - this.one = (new Uint8Array(wasm.memory.buffer, underlying + 1, 1))[0] == 1; - this.two = (new Uint8Array(wasm.memory.buffer, underlying + 2, 1))[0] == 1; - this.few = (new Uint8Array(wasm.memory.buffer, underlying + 3, 1))[0] == 1; - this.many = (new Uint8Array(wasm.memory.buffer, underlying + 4, 1))[0] == 1; - this.other = (new Uint8Array(wasm.memory.buffer, underlying + 5, 1))[0] == 1; - } -} + #zero; + get zero() { + return this.#zero; + } + + #one; + get one() { + return this.#one; + } + + #two; + get two() { + return this.#two; + } + + #few; + get few() { + return this.#few; + } + + #many; + get many() { + return this.#many; + } + + #other; + get other() { + return this.#other; + } + + + // Return this struct in FFI function friendly format. + // Returns an array that can be expanded with spread syntax (...) + + _intoFFI( + slice_cleanup_callbacks, + appendArrayMap + ) { + return [this.#zero, this.#one, this.#two, this.#few, this.#many, this.#other] + } + + // 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. + _fromFFI(ptr) { + const zeroDeref = (new Uint8Array(wasm.memory.buffer, ptr, 1))[0] == 1; + this.#zero = zeroDeref; + const oneDeref = (new Uint8Array(wasm.memory.buffer, ptr + 1, 1))[0] == 1; + this.#one = oneDeref; + const twoDeref = (new Uint8Array(wasm.memory.buffer, ptr + 2, 1))[0] == 1; + this.#two = twoDeref; + const fewDeref = (new Uint8Array(wasm.memory.buffer, ptr + 3, 1))[0] == 1; + this.#few = fewDeref; + const manyDeref = (new Uint8Array(wasm.memory.buffer, ptr + 4, 1))[0] == 1; + this.#many = manyDeref; + const otherDeref = (new Uint8Array(wasm.memory.buffer, ptr + 5, 1))[0] == 1; + this.#other = otherDeref; + + return this; + } + // This is an out struct. You need to call other methods to be able to get this struct. + constructor(ptr) { + this._fromFFI(ptr); + } + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/PluralCategory.d.ts b/ffi/capi/bindings/js/PluralCategory.d.ts index 0f5f3fd97c0..c632202d707 100644 --- a/ffi/capi/bindings/js/PluralCategory.d.ts +++ b/ffi/capi/bindings/js/PluralCategory.d.ts @@ -1,25 +1,31 @@ +// generated by diplomat-tool +import type { pointer, char } from "./diplomat-runtime.d.ts"; + +// Base enumerator definition +/** See the [Rust documentation for `PluralCategory`](https://docs.rs/icu/latest/icu/plurals/enum.PluralCategory.html) for more information. +*/ +export class PluralCategory { + constructor(value : PluralCategory | string); + + get value() : string; + + get ffiValue() : number; + + static Zero : PluralCategory; + + static One : PluralCategory; + + static Two : PluralCategory; + + static Few : PluralCategory; + + static Many : PluralCategory; + + static Other : PluralCategory; + + + static getForCldrString(s: string): PluralCategory | null; + + -/** - - * See the {@link https://docs.rs/icu/latest/icu/plurals/enum.PluralCategory.html Rust documentation for `PluralCategory`} for more information. - */ -export enum PluralCategory { - /** - */ - Zero = 'Zero', - /** - */ - One = 'One', - /** - */ - Two = 'Two', - /** - */ - Few = 'Few', - /** - */ - Many = 'Many', - /** - */ - Other = 'Other', } \ No newline at end of file diff --git a/ffi/capi/bindings/js/PluralCategory.mjs b/ffi/capi/bindings/js/PluralCategory.mjs index 3c01cec5bb2..b39a6e96211 100644 --- a/ffi/capi/bindings/js/PluralCategory.mjs +++ b/ffi/capi/bindings/js/PluralCategory.mjs @@ -1,29 +1,78 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" - -export const PluralCategory_js_to_rust = { - "Zero": 0, - "One": 1, - "Two": 2, - "Few": 3, - "Many": 4, - "Other": 5, -}; - -export const PluralCategory_rust_to_js = { - [0]: "Zero", - [1]: "One", - [2]: "Two", - [3]: "Few", - [4]: "Many", - [5]: "Other", -}; - -export const PluralCategory = { - "Zero": "Zero", - "One": "One", - "Two": "Two", - "Few": "Few", - "Many": "Many", - "Other": "Other", -}; +// generated by diplomat-tool +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; + +// Base enumerator definition +/** See the [Rust documentation for `PluralCategory`](https://docs.rs/icu/latest/icu/plurals/enum.PluralCategory.html) for more information. +*/ +export class PluralCategory { + #value = undefined; + + static values = new Map([ + ["Zero", 0], + ["One", 1], + ["Two", 2], + ["Few", 3], + ["Many", 4], + ["Other", 5] + ]); + constructor(value) { + if (value instanceof PluralCategory) { + this.#value = value.value; + return; + } + + if (PluralCategory.values.has(value)) { + this.#value = value; + return; + } + + throw TypeError(value + " is not a PluralCategory and does not correspond to any of its enumerator values."); + } + + get value() { + return this.#value; + } + + get ffiValue() { + return PluralCategory.values.get(this.#value); + } + + static Zero = new PluralCategory("Zero"); + + static One = new PluralCategory("One"); + + static Two = new PluralCategory("Two"); + + static Few = new PluralCategory("Few"); + + static Many = new PluralCategory("Many"); + + static Other = new PluralCategory("Other"); + + + static getForCldrString(s) { + + const sSlice = diplomatRuntime.DiplomatBuf.str8(wasm, s); + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XPluralCategory_get_for_cldr_string(diplomat_receive_buffer, sSlice.ptr, sSlice.size); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + return null; + } + return PluralCategory[Array.from(PluralCategory.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + } finally { + + sSlice.free(); + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/PluralOperands.d.ts b/ffi/capi/bindings/js/PluralOperands.d.ts index 50a6ab21894..96d50d5e535 100644 --- a/ffi/capi/bindings/js/PluralOperands.d.ts +++ b/ffi/capi/bindings/js/PluralOperands.d.ts @@ -1,27 +1,20 @@ -import { FFIError } from "./diplomat-runtime" -import { FixedDecimal } from "./FixedDecimal"; -import { FixedDecimalParseError } from "./FixedDecimalParseError"; +// generated by diplomat-tool +import type { FixedDecimal } from "./FixedDecimal" +import type { pointer, char } from "./diplomat-runtime.d.ts"; -/** - * See the {@link https://docs.rs/icu/latest/icu/plurals/struct.PluralOperands.html Rust documentation for `PluralOperands`} for more information. - */ +/** See the [Rust documentation for `PluralOperands`](https://docs.rs/icu/latest/icu/plurals/struct.PluralOperands.html) for more information. +*/ export class PluralOperands { + - /** + get ffiValue(): pointer; - * Construct for a given string representing a number - * See the {@link https://docs.rs/icu/latest/icu/plurals/struct.PluralOperands.html#method.from_str Rust documentation for `from_str`} for more information. - * @throws {@link FFIError}<{@link FixedDecimalParseError}> - */ - static create_from_string(s: string): PluralOperands | never; + static createFromString(s: string): PluralOperands; - /** + static createFromFixedDecimal(x: FixedDecimal): PluralOperands; - * Construct from a FixedDecimal + - * Retains at most 18 digits each from the integer and fraction parts. - */ - static create_from_fixed_decimal(x: FixedDecimal): PluralOperands; -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/PluralOperands.mjs b/ffi/capi/bindings/js/PluralOperands.mjs index ffb30e0896f..64fd559aacf 100644 --- a/ffi/capi/bindings/js/PluralOperands.mjs +++ b/ffi/capi/bindings/js/PluralOperands.mjs @@ -1,42 +1,72 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" -import { FixedDecimalParseError_js_to_rust, FixedDecimalParseError_rust_to_js } from "./FixedDecimalParseError.mjs" +// generated by diplomat-tool +import { FixedDecimal } from "./FixedDecimal.mjs" +import { FixedDecimalParseError } from "./FixedDecimalParseError.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -const PluralOperands_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XPluralOperands_destroy(underlying); -}); +/** See the [Rust documentation for `PluralOperands`](https://docs.rs/icu/latest/icu/plurals/struct.PluralOperands.html) for more information. +*/ + +const PluralOperands_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XPluralOperands_destroy(ptr); +}); export class PluralOperands { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - PluralOperands_box_destroy_registry.register(this, underlying); + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + + constructor(ptr, selfEdge) { + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + PluralOperands_box_destroy_registry.register(this, this.#ptr); } - } - - static create_from_string(arg_s) { - const buf_arg_s = diplomatRuntime.DiplomatBuf.str8(wasm, arg_s); - const diplomat_out = (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XPluralOperands_create_from_string(diplomat_receive_buffer, buf_arg_s.ptr, buf_arg_s.size); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new PluralOperands(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = FixedDecimalParseError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - buf_arg_s.free(); - return diplomat_out; - } - - static create_from_fixed_decimal(arg_x) { - return new PluralOperands(wasm.ICU4XPluralOperands_create_from_fixed_decimal(arg_x.underlying), true, []); - } -} + + get ffiValue() { + return this.#ptr; + } + + + static createFromString(s) { + + const sSlice = diplomatRuntime.DiplomatBuf.str8(wasm, s); + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XPluralOperands_create_from_string(diplomat_receive_buffer, sSlice.ptr, sSlice.size); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = FixedDecimalParseError[Array.from(FixedDecimalParseError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('FixedDecimalParseError: ' + cause.value, { cause }); + } + return new PluralOperands(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + sSlice.free(); + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static createFromFixedDecimal(x) { + const result = wasm.ICU4XPluralOperands_create_from_fixed_decimal(x.ffiValue); + + try { + + return new PluralOperands(result, []); + } finally { + + } + } + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/PluralRules.d.ts b/ffi/capi/bindings/js/PluralRules.d.ts index 1b8a4581fd8..32a03d516a4 100644 --- a/ffi/capi/bindings/js/PluralRules.d.ts +++ b/ffi/capi/bindings/js/PluralRules.d.ts @@ -1,48 +1,28 @@ -import { FFIError } from "./diplomat-runtime" -import { DataError } from "./DataError"; -import { DataProvider } from "./DataProvider"; -import { Locale } from "./Locale"; -import { PluralCategories } from "./PluralCategories"; -import { PluralCategory } from "./PluralCategory"; -import { PluralOperands } from "./PluralOperands"; - -/** - - * See the {@link https://docs.rs/icu/latest/icu/plurals/struct.PluralRules.html Rust documentation for `PluralRules`} for more information. - */ -export class PluralRules { - - /** +// generated by diplomat-tool +import type { DataProvider } from "./DataProvider" +import type { Locale } from "./Locale" +import type { PluralCategories } from "./PluralCategories" +import type { PluralCategory } from "./PluralCategory" +import type { PluralOperands } from "./PluralOperands" +import type { pointer, char } from "./diplomat-runtime.d.ts"; - * Construct an {@link PluralRules `PluralRules`} for the given locale, for cardinal numbers - * See the {@link https://docs.rs/icu/latest/icu/plurals/struct.PluralRules.html#method.try_new_cardinal Rust documentation for `try_new_cardinal`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static create_cardinal(provider: DataProvider, locale: Locale): PluralRules | never; - - /** +/** See the [Rust documentation for `PluralRules`](https://docs.rs/icu/latest/icu/plurals/struct.PluralRules.html) for more information. +*/ +export class PluralRules { + - * Construct an {@link PluralRules `PluralRules`} for the given locale, for ordinal numbers + get ffiValue(): pointer; - * See the {@link https://docs.rs/icu/latest/icu/plurals/struct.PluralRules.html#method.try_new_ordinal Rust documentation for `try_new_ordinal`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static create_ordinal(provider: DataProvider, locale: Locale): PluralRules | never; - /** + static createCardinal(provider: DataProvider, locale: Locale): PluralRules; - * Get the category for a given number represented as operands + static createOrdinal(provider: DataProvider, locale: Locale): PluralRules; - * See the {@link https://docs.rs/icu/latest/icu/plurals/struct.PluralRules.html#method.category_for Rust documentation for `category_for`} for more information. - */ - category_for(op: PluralOperands): PluralCategory; + categoryFor(op: PluralOperands): PluralCategory; - /** + get categories(): PluralCategories; - * Get all of the categories needed in the current locale + - * See the {@link https://docs.rs/icu/latest/icu/plurals/struct.PluralRules.html#method.categories Rust documentation for `categories`} for more information. - */ - categories(): PluralCategories; -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/PluralRules.mjs b/ffi/capi/bindings/js/PluralRules.mjs index 31e11e741e0..127cc59acf0 100644 --- a/ffi/capi/bindings/js/PluralRules.mjs +++ b/ffi/capi/bindings/js/PluralRules.mjs @@ -1,68 +1,106 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" -import { DataError_js_to_rust, DataError_rust_to_js } from "./DataError.mjs" +// generated by diplomat-tool +import { DataError } from "./DataError.mjs" +import { DataProvider } from "./DataProvider.mjs" +import { Locale } from "./Locale.mjs" import { PluralCategories } from "./PluralCategories.mjs" -import { PluralCategory_js_to_rust, PluralCategory_rust_to_js } from "./PluralCategory.mjs" +import { PluralCategory } from "./PluralCategory.mjs" +import { PluralOperands } from "./PluralOperands.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -const PluralRules_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XPluralRules_destroy(underlying); -}); +/** See the [Rust documentation for `PluralRules`](https://docs.rs/icu/latest/icu/plurals/struct.PluralRules.html) for more information. +*/ + +const PluralRules_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XPluralRules_destroy(ptr); +}); export class PluralRules { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - PluralRules_box_destroy_registry.register(this, underlying); + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + + constructor(ptr, selfEdge) { + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + PluralRules_box_destroy_registry.register(this, this.#ptr); + } + + get ffiValue() { + return this.#ptr; } - } - static create_cardinal(arg_provider, arg_locale) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XPluralRules_create_cardinal(diplomat_receive_buffer, arg_provider.underlying, arg_locale.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new PluralRules(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - static create_ordinal(arg_provider, arg_locale) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XPluralRules_create_ordinal(diplomat_receive_buffer, arg_provider.underlying, arg_locale.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new PluralRules(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } + static createCardinal(provider, locale) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XPluralRules_create_cardinal(diplomat_receive_buffer, provider.ffiValue, locale.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new PluralRules(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static createOrdinal(provider, locale) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XPluralRules_create_ordinal(diplomat_receive_buffer, provider.ffiValue, locale.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new PluralRules(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + categoryFor(op) { + const result = wasm.ICU4XPluralRules_category_for(this.ffiValue, op.ffiValue); + + try { + + return PluralCategory[Array.from(PluralCategory.values.keys())[result]]; + } finally { + + } + } + + get categories() { + + const diplomat_receive_buffer = wasm.diplomat_alloc(6, 1); + const result = wasm.ICU4XPluralRules_categories(diplomat_receive_buffer, this.ffiValue); + + try { + + return new PluralCategories(diplomat_receive_buffer); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 6, 1); + + } + } - category_for(arg_op) { - return PluralCategory_rust_to_js[wasm.ICU4XPluralRules_category_for(this.underlying, arg_op.underlying)]; - } + - categories() { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(6, 1); - wasm.ICU4XPluralRules_categories(diplomat_receive_buffer, this.underlying); - const out = new PluralCategories(diplomat_receive_buffer); - wasm.diplomat_free(diplomat_receive_buffer, 6, 1); - return out; - })(); - } -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/PropertyValueNameToEnumMapper.d.ts b/ffi/capi/bindings/js/PropertyValueNameToEnumMapper.d.ts index 98d3dba0d77..4a76cdf8ecd 100644 --- a/ffi/capi/bindings/js/PropertyValueNameToEnumMapper.d.ts +++ b/ffi/capi/bindings/js/PropertyValueNameToEnumMapper.d.ts @@ -1,105 +1,44 @@ -import { i16 } from "./diplomat-runtime" -import { FFIError } from "./diplomat-runtime" -import { DataError } from "./DataError"; -import { DataProvider } from "./DataProvider"; +// generated by diplomat-tool +import type { DataProvider } from "./DataProvider" +import type { pointer, char } from "./diplomat-runtime.d.ts"; -/** - * A type capable of looking up a property value from a string name. - - * See the {@link https://docs.rs/icu/latest/icu/properties/names/struct.PropertyValueNameToEnumMapper.html Rust documentation for `PropertyValueNameToEnumMapper`} for more information. - - * See the {@link https://docs.rs/icu/latest/icu/properties/names/struct.PropertyValueNameToEnumMapperBorrowed.html Rust documentation for `PropertyValueNameToEnumMapperBorrowed`} for more information. - */ +/** A type capable of looking up a property value from a string name. +* +*See the [Rust documentation for `PropertyValueNameToEnumMapper`](https://docs.rs/icu/latest/icu/properties/names/struct.PropertyValueNameToEnumMapper.html) for more information. +* +*See the [Rust documentation for `PropertyValueNameToEnumMapperBorrowed`](https://docs.rs/icu/latest/icu/properties/names/struct.PropertyValueNameToEnumMapperBorrowed.html) for more information. +*/ export class PropertyValueNameToEnumMapper { + - /** - - * Get the property value matching the given name, using strict matching - - * Returns -1 if the name is unknown for this property - - * See the {@link https://docs.rs/icu/latest/icu/properties/names/struct.PropertyValueNameToEnumMapperBorrowed.html#method.get_strict Rust documentation for `get_strict`} for more information. - */ - get_strict(name: string): i16; - - /** - - * Get the property value matching the given name, using loose matching - - * Returns -1 if the name is unknown for this property - - * See the {@link https://docs.rs/icu/latest/icu/properties/names/struct.PropertyValueNameToEnumMapperBorrowed.html#method.get_loose Rust documentation for `get_loose`} for more information. - */ - get_loose(name: string): i16; - - /** - - * See the {@link https://docs.rs/icu/latest/icu/properties/struct.GeneralCategory.html#method.name_to_enum_mapper Rust documentation for `name_to_enum_mapper`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_general_category(provider: DataProvider): PropertyValueNameToEnumMapper | never; - - /** - - * See the {@link https://docs.rs/icu/latest/icu/properties/struct.HangulSyllableType.html#method.name_to_enum_mapper Rust documentation for `name_to_enum_mapper`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_hangul_syllable_type(provider: DataProvider): PropertyValueNameToEnumMapper | never; - - /** + get ffiValue(): pointer; - * See the {@link https://docs.rs/icu/latest/icu/properties/struct.EastAsianWidth.html#method.name_to_enum_mapper Rust documentation for `name_to_enum_mapper`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_east_asian_width(provider: DataProvider): PropertyValueNameToEnumMapper | never; - /** + getStrict(name: string): number; - * See the {@link https://docs.rs/icu/latest/icu/properties/struct.BidiClass.html#method.name_to_enum_mapper Rust documentation for `name_to_enum_mapper`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_bidi_class(provider: DataProvider): PropertyValueNameToEnumMapper | never; + getLoose(name: string): number; - /** + static loadGeneralCategory(provider: DataProvider): PropertyValueNameToEnumMapper; - * See the {@link https://docs.rs/icu/latest/icu/properties/struct.IndicSyllabicCategory.html#method.name_to_enum_mapper Rust documentation for `name_to_enum_mapper`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_indic_syllabic_category(provider: DataProvider): PropertyValueNameToEnumMapper | never; + static loadHangulSyllableType(provider: DataProvider): PropertyValueNameToEnumMapper; - /** + static loadEastAsianWidth(provider: DataProvider): PropertyValueNameToEnumMapper; - * See the {@link https://docs.rs/icu/latest/icu/properties/struct.LineBreak.html#method.name_to_enum_mapper Rust documentation for `name_to_enum_mapper`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_line_break(provider: DataProvider): PropertyValueNameToEnumMapper | never; + static loadBidiClass(provider: DataProvider): PropertyValueNameToEnumMapper; - /** + static loadIndicSyllabicCategory(provider: DataProvider): PropertyValueNameToEnumMapper; - * See the {@link https://docs.rs/icu/latest/icu/properties/struct.GraphemeClusterBreak.html#method.name_to_enum_mapper Rust documentation for `name_to_enum_mapper`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_grapheme_cluster_break(provider: DataProvider): PropertyValueNameToEnumMapper | never; + static loadLineBreak(provider: DataProvider): PropertyValueNameToEnumMapper; - /** + static loadGraphemeClusterBreak(provider: DataProvider): PropertyValueNameToEnumMapper; - * See the {@link https://docs.rs/icu/latest/icu/properties/struct.WordBreak.html#method.name_to_enum_mapper Rust documentation for `name_to_enum_mapper`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_word_break(provider: DataProvider): PropertyValueNameToEnumMapper | never; + static loadWordBreak(provider: DataProvider): PropertyValueNameToEnumMapper; - /** + static loadSentenceBreak(provider: DataProvider): PropertyValueNameToEnumMapper; - * See the {@link https://docs.rs/icu/latest/icu/properties/struct.SentenceBreak.html#method.name_to_enum_mapper Rust documentation for `name_to_enum_mapper`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_sentence_break(provider: DataProvider): PropertyValueNameToEnumMapper | never; + static loadScript(provider: DataProvider): PropertyValueNameToEnumMapper; - /** + - * See the {@link https://docs.rs/icu/latest/icu/properties/struct.Script.html#method.name_to_enum_mapper Rust documentation for `name_to_enum_mapper`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_script(provider: DataProvider): PropertyValueNameToEnumMapper | never; -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/PropertyValueNameToEnumMapper.mjs b/ffi/capi/bindings/js/PropertyValueNameToEnumMapper.mjs index 10efddb640b..242fa1789df 100644 --- a/ffi/capi/bindings/js/PropertyValueNameToEnumMapper.mjs +++ b/ffi/capi/bindings/js/PropertyValueNameToEnumMapper.mjs @@ -1,202 +1,262 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" -import { DataError_js_to_rust, DataError_rust_to_js } from "./DataError.mjs" +// generated by diplomat-tool +import { DataError } from "./DataError.mjs" +import { DataProvider } from "./DataProvider.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -const PropertyValueNameToEnumMapper_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XPropertyValueNameToEnumMapper_destroy(underlying); -}); +/** A type capable of looking up a property value from a string name. +* +*See the [Rust documentation for `PropertyValueNameToEnumMapper`](https://docs.rs/icu/latest/icu/properties/names/struct.PropertyValueNameToEnumMapper.html) for more information. +* +*See the [Rust documentation for `PropertyValueNameToEnumMapperBorrowed`](https://docs.rs/icu/latest/icu/properties/names/struct.PropertyValueNameToEnumMapperBorrowed.html) for more information. +*/ + +const PropertyValueNameToEnumMapper_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XPropertyValueNameToEnumMapper_destroy(ptr); +}); export class PropertyValueNameToEnumMapper { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - PropertyValueNameToEnumMapper_box_destroy_registry.register(this, underlying); + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + + constructor(ptr, selfEdge) { + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + PropertyValueNameToEnumMapper_box_destroy_registry.register(this, this.#ptr); + } + + get ffiValue() { + return this.#ptr; + } + + + getStrict(name) { + + const nameSlice = diplomatRuntime.DiplomatBuf.str8(wasm, name); + const result = wasm.ICU4XPropertyValueNameToEnumMapper_get_strict(this.ffiValue, nameSlice.ptr, nameSlice.size); + + try { + + return result; + } finally { + + nameSlice.free(); + + } + } + + getLoose(name) { + + const nameSlice = diplomatRuntime.DiplomatBuf.str8(wasm, name); + const result = wasm.ICU4XPropertyValueNameToEnumMapper_get_loose(this.ffiValue, nameSlice.ptr, nameSlice.size); + + try { + + return result; + } finally { + + nameSlice.free(); + + } + } + + static loadGeneralCategory(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XPropertyValueNameToEnumMapper_load_general_category(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new PropertyValueNameToEnumMapper(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadHangulSyllableType(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XPropertyValueNameToEnumMapper_load_hangul_syllable_type(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new PropertyValueNameToEnumMapper(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadEastAsianWidth(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XPropertyValueNameToEnumMapper_load_east_asian_width(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new PropertyValueNameToEnumMapper(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } } - } - - get_strict(arg_name) { - const buf_arg_name = diplomatRuntime.DiplomatBuf.str8(wasm, arg_name); - const diplomat_out = wasm.ICU4XPropertyValueNameToEnumMapper_get_strict(this.underlying, buf_arg_name.ptr, buf_arg_name.size); - buf_arg_name.free(); - return diplomat_out; - } - - get_loose(arg_name) { - const buf_arg_name = diplomatRuntime.DiplomatBuf.str8(wasm, arg_name); - const diplomat_out = wasm.ICU4XPropertyValueNameToEnumMapper_get_loose(this.underlying, buf_arg_name.ptr, buf_arg_name.size); - buf_arg_name.free(); - return diplomat_out; - } - - static load_general_category(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XPropertyValueNameToEnumMapper_load_general_category(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new PropertyValueNameToEnumMapper(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_hangul_syllable_type(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XPropertyValueNameToEnumMapper_load_hangul_syllable_type(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new PropertyValueNameToEnumMapper(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_east_asian_width(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XPropertyValueNameToEnumMapper_load_east_asian_width(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new PropertyValueNameToEnumMapper(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_bidi_class(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XPropertyValueNameToEnumMapper_load_bidi_class(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new PropertyValueNameToEnumMapper(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_indic_syllabic_category(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XPropertyValueNameToEnumMapper_load_indic_syllabic_category(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new PropertyValueNameToEnumMapper(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_line_break(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XPropertyValueNameToEnumMapper_load_line_break(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new PropertyValueNameToEnumMapper(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_grapheme_cluster_break(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XPropertyValueNameToEnumMapper_load_grapheme_cluster_break(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new PropertyValueNameToEnumMapper(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_word_break(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XPropertyValueNameToEnumMapper_load_word_break(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new PropertyValueNameToEnumMapper(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_sentence_break(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XPropertyValueNameToEnumMapper_load_sentence_break(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new PropertyValueNameToEnumMapper(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_script(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XPropertyValueNameToEnumMapper_load_script(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new PropertyValueNameToEnumMapper(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } -} + + static loadBidiClass(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XPropertyValueNameToEnumMapper_load_bidi_class(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new PropertyValueNameToEnumMapper(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadIndicSyllabicCategory(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XPropertyValueNameToEnumMapper_load_indic_syllabic_category(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new PropertyValueNameToEnumMapper(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadLineBreak(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XPropertyValueNameToEnumMapper_load_line_break(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new PropertyValueNameToEnumMapper(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadGraphemeClusterBreak(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XPropertyValueNameToEnumMapper_load_grapheme_cluster_break(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new PropertyValueNameToEnumMapper(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadWordBreak(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XPropertyValueNameToEnumMapper_load_word_break(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new PropertyValueNameToEnumMapper(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadSentenceBreak(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XPropertyValueNameToEnumMapper_load_sentence_break(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new PropertyValueNameToEnumMapper(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadScript(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XPropertyValueNameToEnumMapper_load_script(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new PropertyValueNameToEnumMapper(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/RegionDisplayNames.d.ts b/ffi/capi/bindings/js/RegionDisplayNames.d.ts index 431fdccc08e..2ed5780165d 100644 --- a/ffi/capi/bindings/js/RegionDisplayNames.d.ts +++ b/ffi/capi/bindings/js/RegionDisplayNames.d.ts @@ -1,30 +1,21 @@ -import { FFIError } from "./diplomat-runtime" -import { DataError } from "./DataError"; -import { DataProvider } from "./DataProvider"; -import { Locale } from "./Locale"; -import { LocaleParseError } from "./LocaleParseError"; +// generated by diplomat-tool +import type { DataProvider } from "./DataProvider" +import type { Locale } from "./Locale" +import type { pointer, char } from "./diplomat-runtime.d.ts"; -/** - * See the {@link https://docs.rs/icu/latest/icu/displaynames/struct.RegionDisplayNames.html Rust documentation for `RegionDisplayNames`} for more information. - */ +/** See the [Rust documentation for `RegionDisplayNames`](https://docs.rs/icu/latest/icu/displaynames/struct.RegionDisplayNames.html) for more information. +*/ export class RegionDisplayNames { + - /** + get ffiValue(): pointer; - * Creates a new `RegionDisplayNames` from locale data and an options bag. - * See the {@link https://docs.rs/icu/latest/icu/displaynames/struct.RegionDisplayNames.html#method.try_new Rust documentation for `try_new`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static create(provider: DataProvider, locale: Locale): RegionDisplayNames | never; + static create(provider: DataProvider, locale: Locale): RegionDisplayNames; - /** + of(region: string): string; - * Returns the locale specific display name of a region. Note that the function returns an empty string in case the display name for a given region code is not found. + - * See the {@link https://docs.rs/icu/latest/icu/displaynames/struct.RegionDisplayNames.html#method.of Rust documentation for `of`} for more information. - * @throws {@link FFIError}<{@link LocaleParseError}> - */ - of(region: string): string | never; -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/RegionDisplayNames.mjs b/ffi/capi/bindings/js/RegionDisplayNames.mjs index e57ef6f274d..e993838e311 100644 --- a/ffi/capi/bindings/js/RegionDisplayNames.mjs +++ b/ffi/capi/bindings/js/RegionDisplayNames.mjs @@ -1,58 +1,86 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" -import { DataError_js_to_rust, DataError_rust_to_js } from "./DataError.mjs" -import { LocaleParseError_js_to_rust, LocaleParseError_rust_to_js } from "./LocaleParseError.mjs" +// generated by diplomat-tool +import { DataError } from "./DataError.mjs" +import { DataProvider } from "./DataProvider.mjs" +import { Locale } from "./Locale.mjs" +import { LocaleParseError } from "./LocaleParseError.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -const RegionDisplayNames_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XRegionDisplayNames_destroy(underlying); -}); +/** See the [Rust documentation for `RegionDisplayNames`](https://docs.rs/icu/latest/icu/displaynames/struct.RegionDisplayNames.html) for more information. +*/ + +const RegionDisplayNames_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XRegionDisplayNames_destroy(ptr); +}); export class RegionDisplayNames { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - RegionDisplayNames_box_destroy_registry.register(this, underlying); + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + + constructor(ptr, selfEdge) { + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + RegionDisplayNames_box_destroy_registry.register(this, this.#ptr); } - } - - static create(arg_provider, arg_locale) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XRegionDisplayNames_create(diplomat_receive_buffer, arg_provider.underlying, arg_locale.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new RegionDisplayNames(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - of(arg_region) { - const buf_arg_region = diplomatRuntime.DiplomatBuf.str8(wasm, arg_region); - const diplomat_out = diplomatRuntime.withDiplomatWrite(wasm, (write) => { - return (() => { + + get ffiValue() { + return this.#ptr; + } + + + static create(provider, locale) { + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XRegionDisplayNames_of(diplomat_receive_buffer, this.underlying, buf_arg_region.ptr, buf_arg_region.size, write); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = {}; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = LocaleParseError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); + const result = wasm.ICU4XRegionDisplayNames_create(diplomat_receive_buffer, provider.ffiValue, locale.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new RegionDisplayNames(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + } - })(); - }); - buf_arg_region.free(); - return diplomat_out; - } -} + } + + of(region) { + + const regionSlice = diplomatRuntime.DiplomatBuf.str8(wasm, region); + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + + const write = wasm.diplomat_buffer_write_create(0); + const result = wasm.ICU4XRegionDisplayNames_of(diplomat_receive_buffer, this.ffiValue, regionSlice.ptr, regionSlice.size, write); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = LocaleParseError[Array.from(LocaleParseError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('LocaleParseError: ' + cause.value, { cause }); + } + return diplomatRuntime.readString8(wasm, wasm.diplomat_buffer_write_get_bytes(write), wasm.diplomat_buffer_write_len(write)); + } finally { + + regionSlice.free(); + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + wasm.diplomat_buffer_write_destroy(write); + + } + } + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/ReorderedIndexMap.d.ts b/ffi/capi/bindings/js/ReorderedIndexMap.d.ts index 8961e8f3c1e..a263dca63ec 100644 --- a/ffi/capi/bindings/js/ReorderedIndexMap.d.ts +++ b/ffi/capi/bindings/js/ReorderedIndexMap.d.ts @@ -1,36 +1,27 @@ -import { usize } from "./diplomat-runtime" +// generated by diplomat-tool +import type { pointer, char } from "./diplomat-runtime.d.ts"; -/** - * Thin wrapper around a vector that maps visual indices to source indices - - * `map[visualIndex] = sourceIndex` - - * Produced by `reorder_visual()` on {@link Bidi `Bidi`}. - */ +/** Thin wrapper around a vector that maps visual indices to source indices +* +*`map[visualIndex] = sourceIndex` +* +*Produced by `reorder_visual()` on [`Bidi`]. +*/ export class ReorderedIndexMap { + - /** + get ffiValue(): pointer; - * Get this as a slice/array of indices - */ - as_slice(): Uint32Array; - /** + get asSlice(): Array; - * The length of this map - */ - len(): usize; + get length(): number; - /** + get isEmpty(): boolean; - * Whether this map is empty - */ - is_empty(): boolean; + get(index: number): number; - /** + - * Get element at `index`. Returns 0 when out of bounds (note that 0 is also a valid in-bounds value, please use `len()` to avoid out-of-bounds) - */ - get(index: usize): usize; -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/ReorderedIndexMap.mjs b/ffi/capi/bindings/js/ReorderedIndexMap.mjs index 7f01bdd5798..229c7d0c6ea 100644 --- a/ffi/capi/bindings/js/ReorderedIndexMap.mjs +++ b/ffi/capi/bindings/js/ReorderedIndexMap.mjs @@ -1,39 +1,91 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" +// generated by diplomat-tool +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -const ReorderedIndexMap_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XReorderedIndexMap_destroy(underlying); -}); +/** Thin wrapper around a vector that maps visual indices to source indices +* +*`map[visualIndex] = sourceIndex` +* +*Produced by `reorder_visual()` on [`Bidi`]. +*/ + +const ReorderedIndexMap_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XReorderedIndexMap_destroy(ptr); +}); export class ReorderedIndexMap { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - ReorderedIndexMap_box_destroy_registry.register(this, underlying); + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + + constructor(ptr, selfEdge) { + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + ReorderedIndexMap_box_destroy_registry.register(this, this.#ptr); + } + + get ffiValue() { + return this.#ptr; + } + + + get asSlice() { + + const diplomat_receive_buffer = wasm.diplomat_alloc(8, 4); + + // This lifetime edge depends on lifetimes 'a + let aEdges = [this]; + const result = wasm.ICU4XReorderedIndexMap_as_slice(diplomat_receive_buffer, this.ffiValue); + + try { + + return diplomatRuntime.DiplomatBuf.sliceFromPtr(wasm, diplomat_receive_buffer, "u32"); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 8, 4); + + } } - } - - as_slice() { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(8, 4); - wasm.ICU4XReorderedIndexMap_as_slice(diplomat_receive_buffer, this.underlying); - const [ptr, size] = new Uint32Array(wasm.memory.buffer, diplomat_receive_buffer, 2); - wasm.diplomat_free(diplomat_receive_buffer, 8, 4); - return Uint32Array.from(new Uint32Array(wasm.memory.buffer, ptr, size)); - })(); - } - - len() { - return wasm.ICU4XReorderedIndexMap_len(this.underlying); - } - - is_empty() { - return wasm.ICU4XReorderedIndexMap_is_empty(this.underlying); - } - - get(arg_index) { - return wasm.ICU4XReorderedIndexMap_get(this.underlying, arg_index); - } -} + + get length() { + const result = wasm.ICU4XReorderedIndexMap_len(this.ffiValue); + + try { + + return result; + } finally { + + } + } + + get isEmpty() { + const result = wasm.ICU4XReorderedIndexMap_is_empty(this.ffiValue); + + try { + + return result; + } finally { + + } + } + + get(index) { + const result = wasm.ICU4XReorderedIndexMap_get(this.ffiValue, index); + + try { + + return result; + } finally { + + } + } + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/ResolvedCollatorOptions.d.ts b/ffi/capi/bindings/js/ResolvedCollatorOptions.d.ts new file mode 100644 index 00000000000..f97f43bae8a --- /dev/null +++ b/ffi/capi/bindings/js/ResolvedCollatorOptions.d.ts @@ -0,0 +1,32 @@ +// generated by diplomat-tool +import type { CollatorAlternateHandling } from "./CollatorAlternateHandling" +import type { CollatorBackwardSecondLevel } from "./CollatorBackwardSecondLevel" +import type { CollatorCaseFirst } from "./CollatorCaseFirst" +import type { CollatorCaseLevel } from "./CollatorCaseLevel" +import type { CollatorMaxVariable } from "./CollatorMaxVariable" +import type { CollatorNumeric } from "./CollatorNumeric" +import type { CollatorStrength } from "./CollatorStrength" +import type { pointer, char } from "./diplomat-runtime.d.ts"; + + +/** See the [Rust documentation for `ResolvedCollatorOptions`](https://docs.rs/icu/latest/icu/collator/struct.ResolvedCollatorOptions.html) for more information. +*/ +export class ResolvedCollatorOptions { + get strength() : CollatorStrength; + + get alternateHandling() : CollatorAlternateHandling; + + get caseFirst() : CollatorCaseFirst; + + get maxVariable() : CollatorMaxVariable; + + get caseLevel() : CollatorCaseLevel; + + get numeric() : CollatorNumeric; + + get backwardSecondLevel() : CollatorBackwardSecondLevel; + + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/ResolvedCollatorOptions.mjs b/ffi/capi/bindings/js/ResolvedCollatorOptions.mjs new file mode 100644 index 00000000000..a8fad204cb8 --- /dev/null +++ b/ffi/capi/bindings/js/ResolvedCollatorOptions.mjs @@ -0,0 +1,91 @@ +// generated by diplomat-tool +import { CollatorAlternateHandling } from "./CollatorAlternateHandling.mjs" +import { CollatorBackwardSecondLevel } from "./CollatorBackwardSecondLevel.mjs" +import { CollatorCaseFirst } from "./CollatorCaseFirst.mjs" +import { CollatorCaseLevel } from "./CollatorCaseLevel.mjs" +import { CollatorMaxVariable } from "./CollatorMaxVariable.mjs" +import { CollatorNumeric } from "./CollatorNumeric.mjs" +import { CollatorStrength } from "./CollatorStrength.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; + + +/** See the [Rust documentation for `ResolvedCollatorOptions`](https://docs.rs/icu/latest/icu/collator/struct.ResolvedCollatorOptions.html) for more information. +*/ +export class ResolvedCollatorOptions { + #strength; + get strength() { + return this.#strength; + } + + #alternateHandling; + get alternateHandling() { + return this.#alternateHandling; + } + + #caseFirst; + get caseFirst() { + return this.#caseFirst; + } + + #maxVariable; + get maxVariable() { + return this.#maxVariable; + } + + #caseLevel; + get caseLevel() { + return this.#caseLevel; + } + + #numeric; + get numeric() { + return this.#numeric; + } + + #backwardSecondLevel; + get backwardSecondLevel() { + return this.#backwardSecondLevel; + } + + + // Return this struct in FFI function friendly format. + // Returns an array that can be expanded with spread syntax (...) + + _intoFFI( + slice_cleanup_callbacks, + appendArrayMap + ) { + return [this.#strength.ffiValue, this.#alternateHandling.ffiValue, this.#caseFirst.ffiValue, this.#maxVariable.ffiValue, this.#caseLevel.ffiValue, this.#numeric.ffiValue, this.#backwardSecondLevel.ffiValue] + } + + // 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. + _fromFFI(ptr) { + const strengthDeref = diplomatRuntime.enumDiscriminant(wasm, ptr); + this.#strength = CollatorStrength[Array.from(CollatorStrength.values.keys())[strengthDeref]]; + const alternateHandlingDeref = diplomatRuntime.enumDiscriminant(wasm, ptr + 4); + this.#alternateHandling = CollatorAlternateHandling[Array.from(CollatorAlternateHandling.values.keys())[alternateHandlingDeref]]; + const caseFirstDeref = diplomatRuntime.enumDiscriminant(wasm, ptr + 8); + this.#caseFirst = CollatorCaseFirst[Array.from(CollatorCaseFirst.values.keys())[caseFirstDeref]]; + const maxVariableDeref = diplomatRuntime.enumDiscriminant(wasm, ptr + 12); + this.#maxVariable = CollatorMaxVariable[Array.from(CollatorMaxVariable.values.keys())[maxVariableDeref]]; + const caseLevelDeref = diplomatRuntime.enumDiscriminant(wasm, ptr + 16); + this.#caseLevel = CollatorCaseLevel[Array.from(CollatorCaseLevel.values.keys())[caseLevelDeref]]; + const numericDeref = diplomatRuntime.enumDiscriminant(wasm, ptr + 20); + this.#numeric = CollatorNumeric[Array.from(CollatorNumeric.values.keys())[numericDeref]]; + const backwardSecondLevelDeref = diplomatRuntime.enumDiscriminant(wasm, ptr + 24); + this.#backwardSecondLevel = CollatorBackwardSecondLevel[Array.from(CollatorBackwardSecondLevel.values.keys())[backwardSecondLevelDeref]]; + + return this; + } + // This is an out struct. You need to call other methods to be able to get this struct. + constructor(ptr) { + this._fromFFI(ptr); + } + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/ScriptExtensionsSet.d.ts b/ffi/capi/bindings/js/ScriptExtensionsSet.d.ts index 81e82b032ce..dd05b2f1a54 100644 --- a/ffi/capi/bindings/js/ScriptExtensionsSet.d.ts +++ b/ffi/capi/bindings/js/ScriptExtensionsSet.d.ts @@ -1,34 +1,23 @@ -import { u16, usize } from "./diplomat-runtime" +// generated by diplomat-tool +import type { pointer, char } from "./diplomat-runtime.d.ts"; -/** - * An object that represents the Script_Extensions property for a single character - - * See the {@link https://docs.rs/icu/latest/icu/properties/script/struct.ScriptExtensionsSet.html Rust documentation for `ScriptExtensionsSet`} for more information. - */ +/** An object that represents the Script_Extensions property for a single character +* +*See the [Rust documentation for `ScriptExtensionsSet`](https://docs.rs/icu/latest/icu/properties/script/struct.ScriptExtensionsSet.html) for more information. +*/ export class ScriptExtensionsSet { + - /** - - * Check if the Script_Extensions property of the given code point covers the given script - - * See the {@link https://docs.rs/icu/latest/icu/properties/script/struct.ScriptExtensionsSet.html#method.contains Rust documentation for `contains`} for more information. - */ - contains(script: u16): boolean; + get ffiValue(): pointer; - /** - * Get the number of scripts contained in here + contains(script: number): boolean; - * See the {@link https://docs.rs/icu/latest/icu/properties/script/struct.ScriptExtensionsSet.html#method.iter Rust documentation for `iter`} for more information. - */ - count(): usize; + get count(): number; - /** + scriptAt(index: number): number | null; - * Get script at index + - * See the {@link https://docs.rs/icu/latest/icu/properties/script/struct.ScriptExtensionsSet.html#method.iter Rust documentation for `iter`} for more information. - */ - script_at(index: usize): u16 | undefined; -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/ScriptExtensionsSet.mjs b/ffi/capi/bindings/js/ScriptExtensionsSet.mjs index 0b6596a2e61..5becfdcb624 100644 --- a/ffi/capi/bindings/js/ScriptExtensionsSet.mjs +++ b/ffi/capi/bindings/js/ScriptExtensionsSet.mjs @@ -1,40 +1,83 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" +// generated by diplomat-tool +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -const ScriptExtensionsSet_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XScriptExtensionsSet_destroy(underlying); -}); +/** An object that represents the Script_Extensions property for a single character +* +*See the [Rust documentation for `ScriptExtensionsSet`](https://docs.rs/icu/latest/icu/properties/script/struct.ScriptExtensionsSet.html) for more information. +*/ + +const ScriptExtensionsSet_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XScriptExtensionsSet_destroy(ptr); +}); export class ScriptExtensionsSet { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - ScriptExtensionsSet_box_destroy_registry.register(this, underlying); + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + #aEdge = []; + + + constructor(ptr, selfEdge, aEdge) { + + + this.#aEdge = aEdge; + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + ScriptExtensionsSet_box_destroy_registry.register(this, this.#ptr); } - } - - contains(arg_script) { - return wasm.ICU4XScriptExtensionsSet_contains(this.underlying, arg_script); - } - - count() { - return wasm.ICU4XScriptExtensionsSet_count(this.underlying); - } - - script_at(arg_index) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(3, 2); - wasm.ICU4XScriptExtensionsSet_script_at(diplomat_receive_buffer, this.underlying, arg_index); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 2); - if (!is_ok) { - wasm.diplomat_free(diplomat_receive_buffer, 3, 2); - return; - } - const value = (new Uint16Array(wasm.memory.buffer, diplomat_receive_buffer, 1))[0]; - wasm.diplomat_free(diplomat_receive_buffer, 3, 2); - return value; - })(); - } -} + + get ffiValue() { + return this.#ptr; + } + + + contains(script) { + const result = wasm.ICU4XScriptExtensionsSet_contains(this.ffiValue, script); + + try { + + return result; + } finally { + + } + } + + get count() { + const result = wasm.ICU4XScriptExtensionsSet_count(this.ffiValue); + + try { + + return result; + } finally { + + } + } + + scriptAt(index) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(3, 2); + const result = wasm.ICU4XScriptExtensionsSet_script_at(diplomat_receive_buffer, this.ffiValue, index); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 2)) { + return null; + } + return (new Uint16Array(wasm.memory.buffer, diplomat_receive_buffer, 1))[0]; + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 3, 2); + + } + } + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/ScriptWithExtensions.d.ts b/ffi/capi/bindings/js/ScriptWithExtensions.d.ts index 911d383f552..ce13869d7f1 100644 --- a/ffi/capi/bindings/js/ScriptWithExtensions.d.ts +++ b/ffi/capi/bindings/js/ScriptWithExtensions.d.ts @@ -1,54 +1,30 @@ -import { u16, u32 } from "./diplomat-runtime" -import { FFIError } from "./diplomat-runtime" -import { CodePointRangeIterator } from "./CodePointRangeIterator"; -import { DataError } from "./DataError"; -import { DataProvider } from "./DataProvider"; -import { ScriptWithExtensionsBorrowed } from "./ScriptWithExtensionsBorrowed"; +// generated by diplomat-tool +import type { CodePointRangeIterator } from "./CodePointRangeIterator" +import type { DataProvider } from "./DataProvider" +import type { ScriptWithExtensionsBorrowed } from "./ScriptWithExtensionsBorrowed" +import type { pointer, char } from "./diplomat-runtime.d.ts"; -/** - * An ICU4X ScriptWithExtensions map object, capable of holding a map of codepoints to scriptextensions values - - * See the {@link https://docs.rs/icu/latest/icu/properties/script/struct.ScriptWithExtensions.html Rust documentation for `ScriptWithExtensions`} for more information. - */ +/** An ICU4X ScriptWithExtensions map object, capable of holding a map of codepoints to scriptextensions values +* +*See the [Rust documentation for `ScriptWithExtensions`](https://docs.rs/icu/latest/icu/properties/script/struct.ScriptWithExtensions.html) for more information. +*/ export class ScriptWithExtensions { + - /** - - * See the {@link https://docs.rs/icu/latest/icu/properties/script/fn.script_with_extensions.html Rust documentation for `script_with_extensions`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static create(provider: DataProvider): ScriptWithExtensions | never; - - /** - - * Get the Script property value for a code point - - * See the {@link https://docs.rs/icu/latest/icu/properties/script/struct.ScriptWithExtensionsBorrowed.html#method.get_script_val Rust documentation for `get_script_val`} for more information. - */ - get_script_val(code_point: u32): u16; - - /** + get ffiValue(): pointer; - * Check if the Script_Extensions property of the given code point covers the given script - * See the {@link https://docs.rs/icu/latest/icu/properties/script/struct.ScriptWithExtensionsBorrowed.html#method.has_script Rust documentation for `has_script`} for more information. - */ - has_script(code_point: u32, script: u16): boolean; + static create(provider: DataProvider): ScriptWithExtensions; - /** + getScriptVal(codePoint: number): number; - * Borrow this object for a slightly faster variant with more operations + hasScript(codePoint: number, script: number): boolean; - * See the {@link https://docs.rs/icu/latest/icu/properties/script/struct.ScriptWithExtensions.html#method.as_borrowed Rust documentation for `as_borrowed`} for more information. - */ - as_borrowed(): ScriptWithExtensionsBorrowed; + get asBorrowed(): ScriptWithExtensionsBorrowed; - /** + iterRangesForScript(script: number): CodePointRangeIterator; - * Get a list of ranges of code points that contain this script in their Script_Extensions values + - * See the {@link https://docs.rs/icu/latest/icu/properties/script/struct.ScriptWithExtensionsBorrowed.html#method.get_script_extensions_ranges Rust documentation for `get_script_extensions_ranges`} for more information. - */ - iter_ranges_for_script(script: u16): CodePointRangeIterator; -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/ScriptWithExtensions.mjs b/ffi/capi/bindings/js/ScriptWithExtensions.mjs index d1e218a9a9d..d986bf148f5 100644 --- a/ffi/capi/bindings/js/ScriptWithExtensions.mjs +++ b/ffi/capi/bindings/js/ScriptWithExtensions.mjs @@ -1,53 +1,111 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" +// generated by diplomat-tool import { CodePointRangeIterator } from "./CodePointRangeIterator.mjs" -import { DataError_js_to_rust, DataError_rust_to_js } from "./DataError.mjs" +import { DataError } from "./DataError.mjs" +import { DataProvider } from "./DataProvider.mjs" import { ScriptWithExtensionsBorrowed } from "./ScriptWithExtensionsBorrowed.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -const ScriptWithExtensions_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XScriptWithExtensions_destroy(underlying); -}); +/** An ICU4X ScriptWithExtensions map object, capable of holding a map of codepoints to scriptextensions values +* +*See the [Rust documentation for `ScriptWithExtensions`](https://docs.rs/icu/latest/icu/properties/script/struct.ScriptWithExtensions.html) for more information. +*/ + +const ScriptWithExtensions_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XScriptWithExtensions_destroy(ptr); +}); export class ScriptWithExtensions { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - ScriptWithExtensions_box_destroy_registry.register(this, underlying); + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + + constructor(ptr, selfEdge) { + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + ScriptWithExtensions_box_destroy_registry.register(this, this.#ptr); + } + + get ffiValue() { + return this.#ptr; } - } - - static create(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XScriptWithExtensions_create(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new ScriptWithExtensions(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - get_script_val(arg_code_point) { - return wasm.ICU4XScriptWithExtensions_get_script_val(this.underlying, arg_code_point); - } - - has_script(arg_code_point, arg_script) { - return wasm.ICU4XScriptWithExtensions_has_script(this.underlying, arg_code_point, arg_script); - } - - as_borrowed() { - return new ScriptWithExtensionsBorrowed(wasm.ICU4XScriptWithExtensions_as_borrowed(this.underlying), true, [this]); - } - - iter_ranges_for_script(arg_script) { - return new CodePointRangeIterator(wasm.ICU4XScriptWithExtensions_iter_ranges_for_script(this.underlying, arg_script), true, [this]); - } -} + + + static create(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XScriptWithExtensions_create(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new ScriptWithExtensions(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + getScriptVal(codePoint) { + const result = wasm.ICU4XScriptWithExtensions_get_script_val(this.ffiValue, codePoint); + + try { + + return result; + } finally { + + } + } + + hasScript(codePoint, script) { + const result = wasm.ICU4XScriptWithExtensions_has_script(this.ffiValue, codePoint, script); + + try { + + return result; + } finally { + + } + } + + get asBorrowed() { + + // This lifetime edge depends on lifetimes 'a + let aEdges = [this]; + const result = wasm.ICU4XScriptWithExtensions_as_borrowed(this.ffiValue); + + try { + + return new ScriptWithExtensionsBorrowed(result, [], aEdges); + } finally { + + } + } + + iterRangesForScript(script) { + + // This lifetime edge depends on lifetimes 'a + let aEdges = [this]; + const result = wasm.ICU4XScriptWithExtensions_iter_ranges_for_script(this.ffiValue, script); + + try { + + return new CodePointRangeIterator(result, [], aEdges); + } finally { + + } + } + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/ScriptWithExtensionsBorrowed.d.ts b/ffi/capi/bindings/js/ScriptWithExtensionsBorrowed.d.ts index 4ed5330a6c0..d8f33d90c01 100644 --- a/ffi/capi/bindings/js/ScriptWithExtensionsBorrowed.d.ts +++ b/ffi/capi/bindings/js/ScriptWithExtensionsBorrowed.d.ts @@ -1,44 +1,27 @@ -import { u16, u32 } from "./diplomat-runtime" -import { CodePointSetData } from "./CodePointSetData"; -import { ScriptExtensionsSet } from "./ScriptExtensionsSet"; +// generated by diplomat-tool +import type { CodePointSetData } from "./CodePointSetData" +import type { ScriptExtensionsSet } from "./ScriptExtensionsSet" +import type { pointer, char } from "./diplomat-runtime.d.ts"; -/** - * A slightly faster ScriptWithExtensions object - - * See the {@link https://docs.rs/icu/latest/icu/properties/script/struct.ScriptWithExtensionsBorrowed.html Rust documentation for `ScriptWithExtensionsBorrowed`} for more information. - */ +/** A slightly faster ScriptWithExtensions object +* +*See the [Rust documentation for `ScriptWithExtensionsBorrowed`](https://docs.rs/icu/latest/icu/properties/script/struct.ScriptWithExtensionsBorrowed.html) for more information. +*/ export class ScriptWithExtensionsBorrowed { + - /** - - * Get the Script property value for a code point - - * See the {@link https://docs.rs/icu/latest/icu/properties/script/struct.ScriptWithExtensionsBorrowed.html#method.get_script_val Rust documentation for `get_script_val`} for more information. - */ - get_script_val(code_point: u32): u16; - - /** - - * Get the Script property value for a code point + get ffiValue(): pointer; - * See the {@link https://docs.rs/icu/latest/icu/properties/script/struct.ScriptWithExtensionsBorrowed.html#method.get_script_extensions_val Rust documentation for `get_script_extensions_val`} for more information. - */ - get_script_extensions_val(code_point: u32): ScriptExtensionsSet; - /** + getScriptVal(codePoint: number): number; - * Check if the Script_Extensions property of the given code point covers the given script + getScriptExtensionsVal(codePoint: number): ScriptExtensionsSet; - * See the {@link https://docs.rs/icu/latest/icu/properties/script/struct.ScriptWithExtensionsBorrowed.html#method.has_script Rust documentation for `has_script`} for more information. - */ - has_script(code_point: u32, script: u16): boolean; + hasScript(codePoint: number, script: number): boolean; - /** + getScriptExtensionsSet(script: number): CodePointSetData; - * Build the CodePointSetData corresponding to a codepoints matching a particular script in their Script_Extensions + - * See the {@link https://docs.rs/icu/latest/icu/properties/script/struct.ScriptWithExtensionsBorrowed.html#method.get_script_extensions_set Rust documentation for `get_script_extensions_set`} for more information. - */ - get_script_extensions_set(script: u16): CodePointSetData; -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/ScriptWithExtensionsBorrowed.mjs b/ffi/capi/bindings/js/ScriptWithExtensionsBorrowed.mjs index 520bfa910ad..5c1c822438f 100644 --- a/ffi/capi/bindings/js/ScriptWithExtensionsBorrowed.mjs +++ b/ffi/capi/bindings/js/ScriptWithExtensionsBorrowed.mjs @@ -1,35 +1,92 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" +// generated by diplomat-tool import { CodePointSetData } from "./CodePointSetData.mjs" import { ScriptExtensionsSet } from "./ScriptExtensionsSet.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -const ScriptWithExtensionsBorrowed_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XScriptWithExtensionsBorrowed_destroy(underlying); -}); +/** A slightly faster ScriptWithExtensions object +* +*See the [Rust documentation for `ScriptWithExtensionsBorrowed`](https://docs.rs/icu/latest/icu/properties/script/struct.ScriptWithExtensionsBorrowed.html) for more information. +*/ + +const ScriptWithExtensionsBorrowed_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XScriptWithExtensionsBorrowed_destroy(ptr); +}); export class ScriptWithExtensionsBorrowed { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - ScriptWithExtensionsBorrowed_box_destroy_registry.register(this, underlying); + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + #aEdge = []; + + + constructor(ptr, selfEdge, aEdge) { + + + this.#aEdge = aEdge; + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + ScriptWithExtensionsBorrowed_box_destroy_registry.register(this, this.#ptr); + } + + get ffiValue() { + return this.#ptr; } - } - get_script_val(arg_code_point) { - return wasm.ICU4XScriptWithExtensionsBorrowed_get_script_val(this.underlying, arg_code_point); - } - get_script_extensions_val(arg_code_point) { - return new ScriptExtensionsSet(wasm.ICU4XScriptWithExtensionsBorrowed_get_script_extensions_val(this.underlying, arg_code_point), true, [this]); - } + getScriptVal(codePoint) { + const result = wasm.ICU4XScriptWithExtensionsBorrowed_get_script_val(this.ffiValue, codePoint); + + try { + + return result; + } finally { + + } + } + + getScriptExtensionsVal(codePoint) { + + // This lifetime edge depends on lifetimes 'a + let aEdges = [this]; + const result = wasm.ICU4XScriptWithExtensionsBorrowed_get_script_extensions_val(this.ffiValue, codePoint); + + try { + + return new ScriptExtensionsSet(result, [], aEdges); + } finally { + + } + } + + hasScript(codePoint, script) { + const result = wasm.ICU4XScriptWithExtensionsBorrowed_has_script(this.ffiValue, codePoint, script); + + try { + + return result; + } finally { + + } + } + + getScriptExtensionsSet(script) { + const result = wasm.ICU4XScriptWithExtensionsBorrowed_get_script_extensions_set(this.ffiValue, script); + + try { + + return new CodePointSetData(result, []); + } finally { + + } + } - has_script(arg_code_point, arg_script) { - return wasm.ICU4XScriptWithExtensionsBorrowed_has_script(this.underlying, arg_code_point, arg_script); - } + - get_script_extensions_set(arg_script) { - return new CodePointSetData(wasm.ICU4XScriptWithExtensionsBorrowed_get_script_extensions_set(this.underlying, arg_script), true, []); - } -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/SegmenterWordType.d.ts b/ffi/capi/bindings/js/SegmenterWordType.d.ts index 31fceab3535..48552e853f6 100644 --- a/ffi/capi/bindings/js/SegmenterWordType.d.ts +++ b/ffi/capi/bindings/js/SegmenterWordType.d.ts @@ -1,16 +1,25 @@ +// generated by diplomat-tool +import type { pointer, char } from "./diplomat-runtime.d.ts"; + +// Base enumerator definition +/** See the [Rust documentation for `WordType`](https://docs.rs/icu/latest/icu/segmenter/enum.WordType.html) for more information. +*/ +export class SegmenterWordType { + constructor(value : SegmenterWordType | string); + + get value() : string; + + get ffiValue() : number; + + static None : SegmenterWordType; + + static Number : SegmenterWordType; + + static Letter : SegmenterWordType; + + + get isWordLike(): boolean; + + -/** - - * See the {@link https://docs.rs/icu/latest/icu/segmenter/enum.WordType.html Rust documentation for `WordType`} for more information. - */ -export enum SegmenterWordType { - /** - */ - None = 'None', - /** - */ - Number = 'Number', - /** - */ - Letter = 'Letter', } \ No newline at end of file diff --git a/ffi/capi/bindings/js/SegmenterWordType.mjs b/ffi/capi/bindings/js/SegmenterWordType.mjs index 4ab9138f31a..089cbb8dadf 100644 --- a/ffi/capi/bindings/js/SegmenterWordType.mjs +++ b/ffi/capi/bindings/js/SegmenterWordType.mjs @@ -1,20 +1,58 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" - -export const SegmenterWordType_js_to_rust = { - "None": 0, - "Number": 1, - "Letter": 2, -}; - -export const SegmenterWordType_rust_to_js = { - [0]: "None", - [1]: "Number", - [2]: "Letter", -}; - -export const SegmenterWordType = { - "None": "None", - "Number": "Number", - "Letter": "Letter", -}; +// generated by diplomat-tool +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; + +// Base enumerator definition +/** See the [Rust documentation for `WordType`](https://docs.rs/icu/latest/icu/segmenter/enum.WordType.html) for more information. +*/ +export class SegmenterWordType { + #value = undefined; + + static values = new Map([ + ["None", 0], + ["Number", 1], + ["Letter", 2] + ]); + constructor(value) { + if (value instanceof SegmenterWordType) { + this.#value = value.value; + return; + } + + if (SegmenterWordType.values.has(value)) { + this.#value = value; + return; + } + + throw TypeError(value + " is not a SegmenterWordType and does not correspond to any of its enumerator values."); + } + + get value() { + return this.#value; + } + + get ffiValue() { + return SegmenterWordType.values.get(this.#value); + } + + static None = new SegmenterWordType("None"); + + static Number = new SegmenterWordType("Number"); + + static Letter = new SegmenterWordType("Letter"); + + + get isWordLike() { + const result = wasm.ICU4XSegmenterWordType_is_word_like(this.ffiValue); + + try { + + return result; + } finally { + + } + } + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/SentenceBreakIteratorLatin1.d.ts b/ffi/capi/bindings/js/SentenceBreakIteratorLatin1.d.ts index 89dc0170a70..0342df5911f 100644 --- a/ffi/capi/bindings/js/SentenceBreakIteratorLatin1.d.ts +++ b/ffi/capi/bindings/js/SentenceBreakIteratorLatin1.d.ts @@ -1,16 +1,17 @@ -import { i32 } from "./diplomat-runtime" +// generated by diplomat-tool +import type { pointer, char } from "./diplomat-runtime.d.ts"; -/** - * See the {@link https://docs.rs/icu/latest/icu/segmenter/struct.SentenceBreakIterator.html Rust documentation for `SentenceBreakIterator`} for more information. - */ +/** See the [Rust documentation for `SentenceBreakIterator`](https://docs.rs/icu/latest/icu/segmenter/struct.SentenceBreakIterator.html) for more information. +*/ export class SentenceBreakIteratorLatin1 { + - /** + get ffiValue(): pointer; - * Finds the next breakpoint. Returns -1 if at the end of the string or if the index is out of range of a 32-bit signed integer. - * See the {@link https://docs.rs/icu/latest/icu/segmenter/struct.SentenceBreakIterator.html#method.next Rust documentation for `next`} for more information. - */ - next(): i32; -} + next(): number; + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/SentenceBreakIteratorLatin1.mjs b/ffi/capi/bindings/js/SentenceBreakIteratorLatin1.mjs index e03af236132..53094411b9b 100644 --- a/ffi/capi/bindings/js/SentenceBreakIteratorLatin1.mjs +++ b/ffi/capi/bindings/js/SentenceBreakIteratorLatin1.mjs @@ -1,21 +1,52 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" +// generated by diplomat-tool +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -const SentenceBreakIteratorLatin1_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XSentenceBreakIteratorLatin1_destroy(underlying); -}); +/** See the [Rust documentation for `SentenceBreakIterator`](https://docs.rs/icu/latest/icu/segmenter/struct.SentenceBreakIterator.html) for more information. +*/ + +const SentenceBreakIteratorLatin1_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XSentenceBreakIteratorLatin1_destroy(ptr); +}); export class SentenceBreakIteratorLatin1 { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - SentenceBreakIteratorLatin1_box_destroy_registry.register(this, underlying); + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + #aEdge = []; + + + constructor(ptr, selfEdge, aEdge) { + + + this.#aEdge = aEdge; + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + SentenceBreakIteratorLatin1_box_destroy_registry.register(this, this.#ptr); + } + + get ffiValue() { + return this.#ptr; } - } - next() { - return wasm.ICU4XSentenceBreakIteratorLatin1_next(this.underlying); - } -} + + next() { + const result = wasm.ICU4XSentenceBreakIteratorLatin1_next(this.ffiValue); + + try { + + return result; + } finally { + + } + } + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/SentenceBreakIteratorUtf16.d.ts b/ffi/capi/bindings/js/SentenceBreakIteratorUtf16.d.ts index bba37b9afb2..0327e833016 100644 --- a/ffi/capi/bindings/js/SentenceBreakIteratorUtf16.d.ts +++ b/ffi/capi/bindings/js/SentenceBreakIteratorUtf16.d.ts @@ -1,16 +1,17 @@ -import { i32 } from "./diplomat-runtime" +// generated by diplomat-tool +import type { pointer, char } from "./diplomat-runtime.d.ts"; -/** - * See the {@link https://docs.rs/icu/latest/icu/segmenter/struct.SentenceBreakIterator.html Rust documentation for `SentenceBreakIterator`} for more information. - */ +/** See the [Rust documentation for `SentenceBreakIterator`](https://docs.rs/icu/latest/icu/segmenter/struct.SentenceBreakIterator.html) for more information. +*/ export class SentenceBreakIteratorUtf16 { + - /** + get ffiValue(): pointer; - * Finds the next breakpoint. Returns -1 if at the end of the string or if the index is out of range of a 32-bit signed integer. - * See the {@link https://docs.rs/icu/latest/icu/segmenter/struct.SentenceBreakIterator.html#method.next Rust documentation for `next`} for more information. - */ - next(): i32; -} + next(): number; + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/SentenceBreakIteratorUtf16.mjs b/ffi/capi/bindings/js/SentenceBreakIteratorUtf16.mjs index a8b9c219c37..77017f73784 100644 --- a/ffi/capi/bindings/js/SentenceBreakIteratorUtf16.mjs +++ b/ffi/capi/bindings/js/SentenceBreakIteratorUtf16.mjs @@ -1,21 +1,52 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" +// generated by diplomat-tool +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -const SentenceBreakIteratorUtf16_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XSentenceBreakIteratorUtf16_destroy(underlying); -}); +/** See the [Rust documentation for `SentenceBreakIterator`](https://docs.rs/icu/latest/icu/segmenter/struct.SentenceBreakIterator.html) for more information. +*/ + +const SentenceBreakIteratorUtf16_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XSentenceBreakIteratorUtf16_destroy(ptr); +}); export class SentenceBreakIteratorUtf16 { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - SentenceBreakIteratorUtf16_box_destroy_registry.register(this, underlying); + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + #aEdge = []; + + + constructor(ptr, selfEdge, aEdge) { + + + this.#aEdge = aEdge; + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + SentenceBreakIteratorUtf16_box_destroy_registry.register(this, this.#ptr); + } + + get ffiValue() { + return this.#ptr; } - } - next() { - return wasm.ICU4XSentenceBreakIteratorUtf16_next(this.underlying); - } -} + + next() { + const result = wasm.ICU4XSentenceBreakIteratorUtf16_next(this.ffiValue); + + try { + + return result; + } finally { + + } + } + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/SentenceBreakIteratorUtf8.d.ts b/ffi/capi/bindings/js/SentenceBreakIteratorUtf8.d.ts index a67dfc05756..685b429b912 100644 --- a/ffi/capi/bindings/js/SentenceBreakIteratorUtf8.d.ts +++ b/ffi/capi/bindings/js/SentenceBreakIteratorUtf8.d.ts @@ -1,16 +1,17 @@ -import { i32 } from "./diplomat-runtime" +// generated by diplomat-tool +import type { pointer, char } from "./diplomat-runtime.d.ts"; -/** - * See the {@link https://docs.rs/icu/latest/icu/segmenter/struct.SentenceBreakIterator.html Rust documentation for `SentenceBreakIterator`} for more information. - */ +/** See the [Rust documentation for `SentenceBreakIterator`](https://docs.rs/icu/latest/icu/segmenter/struct.SentenceBreakIterator.html) for more information. +*/ export class SentenceBreakIteratorUtf8 { + - /** + get ffiValue(): pointer; - * Finds the next breakpoint. Returns -1 if at the end of the string or if the index is out of range of a 32-bit signed integer. - * See the {@link https://docs.rs/icu/latest/icu/segmenter/struct.SentenceBreakIterator.html#method.next Rust documentation for `next`} for more information. - */ - next(): i32; -} + next(): number; + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/SentenceBreakIteratorUtf8.mjs b/ffi/capi/bindings/js/SentenceBreakIteratorUtf8.mjs index 7b46d6b7d41..ed9324c7a4c 100644 --- a/ffi/capi/bindings/js/SentenceBreakIteratorUtf8.mjs +++ b/ffi/capi/bindings/js/SentenceBreakIteratorUtf8.mjs @@ -1,21 +1,52 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" +// generated by diplomat-tool +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -const SentenceBreakIteratorUtf8_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XSentenceBreakIteratorUtf8_destroy(underlying); -}); +/** See the [Rust documentation for `SentenceBreakIterator`](https://docs.rs/icu/latest/icu/segmenter/struct.SentenceBreakIterator.html) for more information. +*/ + +const SentenceBreakIteratorUtf8_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XSentenceBreakIteratorUtf8_destroy(ptr); +}); export class SentenceBreakIteratorUtf8 { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - SentenceBreakIteratorUtf8_box_destroy_registry.register(this, underlying); + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + #aEdge = []; + + + constructor(ptr, selfEdge, aEdge) { + + + this.#aEdge = aEdge; + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + SentenceBreakIteratorUtf8_box_destroy_registry.register(this, this.#ptr); + } + + get ffiValue() { + return this.#ptr; } - } - next() { - return wasm.ICU4XSentenceBreakIteratorUtf8_next(this.underlying); - } -} + + next() { + const result = wasm.ICU4XSentenceBreakIteratorUtf8_next(this.ffiValue); + + try { + + return result; + } finally { + + } + } + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/SentenceSegmenter.d.ts b/ffi/capi/bindings/js/SentenceSegmenter.d.ts index 51460e35303..71ab687108a 100644 --- a/ffi/capi/bindings/js/SentenceSegmenter.d.ts +++ b/ffi/capi/bindings/js/SentenceSegmenter.d.ts @@ -1,52 +1,23 @@ -import { FFIError } from "./diplomat-runtime" -import { DataError } from "./DataError"; -import { DataProvider } from "./DataProvider"; -import { SentenceBreakIteratorLatin1 } from "./SentenceBreakIteratorLatin1"; -import { SentenceBreakIteratorUtf16 } from "./SentenceBreakIteratorUtf16"; -import { SentenceBreakIteratorUtf8 } from "./SentenceBreakIteratorUtf8"; +// generated by diplomat-tool +import type { DataProvider } from "./DataProvider" +import type { SentenceBreakIteratorUtf16 } from "./SentenceBreakIteratorUtf16" +import type { pointer, char } from "./diplomat-runtime.d.ts"; -/** - * An ICU4X sentence-break segmenter, capable of finding sentence breakpoints in strings. - - * See the {@link https://docs.rs/icu/latest/icu/segmenter/struct.SentenceSegmenter.html Rust documentation for `SentenceSegmenter`} for more information. - */ +/** An ICU4X sentence-break segmenter, capable of finding sentence breakpoints in strings. +* +*See the [Rust documentation for `SentenceSegmenter`](https://docs.rs/icu/latest/icu/segmenter/struct.SentenceSegmenter.html) for more information. +*/ export class SentenceSegmenter { + - /** - - * Construct an {@link SentenceSegmenter `SentenceSegmenter`}. - - * See the {@link https://docs.rs/icu/latest/icu/segmenter/struct.SentenceSegmenter.html#method.new Rust documentation for `new`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static create(provider: DataProvider): SentenceSegmenter | never; - - /** - - * Segments a string. - - * Ill-formed input is treated as if errors had been replaced with REPLACEMENT CHARACTERs according to the WHATWG Encoding Standard. - - * See the {@link https://docs.rs/icu/latest/icu/segmenter/struct.SentenceSegmenter.html#method.segment_utf8 Rust documentation for `segment_utf8`} for more information. - */ - segment_utf8(input: string): SentenceBreakIteratorUtf8; - - /** - - * Segments a string. + get ffiValue(): pointer; - * Ill-formed input is treated as if errors had been replaced with REPLACEMENT CHARACTERs according to the WHATWG Encoding Standard. - * See the {@link https://docs.rs/icu/latest/icu/segmenter/struct.SentenceSegmenter.html#method.segment_utf16 Rust documentation for `segment_utf16`} for more information. - */ - segment_utf16(input: string): SentenceBreakIteratorUtf16; + static create(provider: DataProvider): SentenceSegmenter; - /** + segment(input: string): SentenceBreakIteratorUtf16; - * Segments a Latin-1 string. + - * See the {@link https://docs.rs/icu/latest/icu/segmenter/struct.SentenceSegmenter.html#method.segment_latin1 Rust documentation for `segment_latin1`} for more information. - */ - segment_latin1(input: Uint8Array): SentenceBreakIteratorLatin1; -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/SentenceSegmenter.mjs b/ffi/capi/bindings/js/SentenceSegmenter.mjs index a004d443b6d..eea6050f7da 100644 --- a/ffi/capi/bindings/js/SentenceSegmenter.mjs +++ b/ffi/capi/bindings/js/SentenceSegmenter.mjs @@ -1,59 +1,78 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" -import { DataError_js_to_rust, DataError_rust_to_js } from "./DataError.mjs" -import { SentenceBreakIteratorLatin1 } from "./SentenceBreakIteratorLatin1.mjs" +// generated by diplomat-tool +import { DataError } from "./DataError.mjs" +import { DataProvider } from "./DataProvider.mjs" import { SentenceBreakIteratorUtf16 } from "./SentenceBreakIteratorUtf16.mjs" -import { SentenceBreakIteratorUtf8 } from "./SentenceBreakIteratorUtf8.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -const SentenceSegmenter_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XSentenceSegmenter_destroy(underlying); -}); +/** An ICU4X sentence-break segmenter, capable of finding sentence breakpoints in strings. +* +*See the [Rust documentation for `SentenceSegmenter`](https://docs.rs/icu/latest/icu/segmenter/struct.SentenceSegmenter.html) for more information. +*/ + +const SentenceSegmenter_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XSentenceSegmenter_destroy(ptr); +}); export class SentenceSegmenter { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - SentenceSegmenter_box_destroy_registry.register(this, underlying); + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + + constructor(ptr, selfEdge) { + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + SentenceSegmenter_box_destroy_registry.register(this, this.#ptr); } - } - - static create(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XSentenceSegmenter_create(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new SentenceSegmenter(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - segment_utf8(arg_input) { - const buf_arg_input = diplomatRuntime.DiplomatBuf.str8(wasm, arg_input); - const diplomat_out = new SentenceBreakIteratorUtf8(wasm.ICU4XSentenceSegmenter_segment_utf8(this.underlying, buf_arg_input.ptr, buf_arg_input.size), true, [this, buf_arg_input]); - buf_arg_input.garbageCollect(); - return diplomat_out; - } - - segment_utf16(arg_input) { - const buf_arg_input = diplomatRuntime.DiplomatBuf.str16(wasm, arg_input); - const diplomat_out = new SentenceBreakIteratorUtf16(wasm.ICU4XSentenceSegmenter_segment_utf16(this.underlying, buf_arg_input.ptr, buf_arg_input.size), true, [this, buf_arg_input]); - buf_arg_input.garbageCollect(); - return diplomat_out; - } - - segment_latin1(arg_input) { - const buf_arg_input = diplomatRuntime.DiplomatBuf.slice(wasm, arg_input, "u8"); - const diplomat_out = new SentenceBreakIteratorLatin1(wasm.ICU4XSentenceSegmenter_segment_latin1(this.underlying, buf_arg_input.ptr, buf_arg_input.size), true, [this, buf_arg_input]); - buf_arg_input.garbageCollect(); - return diplomat_out; - } -} + + get ffiValue() { + return this.#ptr; + } + + + static create(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XSentenceSegmenter_create(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new SentenceSegmenter(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + segment(input) { + + const inputSlice = diplomatRuntime.DiplomatBuf.str16(wasm, input); + + // This lifetime edge depends on lifetimes 'a + let aEdges = [this, inputSlice]; + const result = wasm.ICU4XSentenceSegmenter_segment_utf16(this.ffiValue, inputSlice.ptr, inputSlice.size); + + try { + + return new SentenceBreakIteratorUtf16(result, [], aEdges); + } finally { + + inputSlice.garbageCollect(); + + } + } + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/Time.d.ts b/ffi/capi/bindings/js/Time.d.ts index 98518f81289..e6a8a677e25 100644 --- a/ffi/capi/bindings/js/Time.d.ts +++ b/ffi/capi/bindings/js/Time.d.ts @@ -1,62 +1,29 @@ -import { u8, u32 } from "./diplomat-runtime" -import { FFIError } from "./diplomat-runtime" -import { CalendarError } from "./CalendarError"; +// generated by diplomat-tool +import type { pointer, char } from "./diplomat-runtime.d.ts"; -/** - * An ICU4X Time object representing a time in terms of hour, minute, second, nanosecond - - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.Time.html Rust documentation for `Time`} for more information. - */ +/** An ICU4X Time object representing a time in terms of hour, minute, second, nanosecond +* +*See the [Rust documentation for `Time`](https://docs.rs/icu/latest/icu/calendar/struct.Time.html) for more information. +*/ export class Time { + - /** - - * Creates a new {@link Time `Time`} given field values - - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.Time.html#method.try_new Rust documentation for `try_new`} for more information. - * @throws {@link FFIError}<{@link CalendarError}> - */ - static create(hour: u8, minute: u8, second: u8, nanosecond: u32): Time | never; - - /** - - * Creates a new {@link Time `Time`} representing midnight (00:00.000). - - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.Time.html#method.midnight Rust documentation for `midnight`} for more information. - * @throws {@link FFIError}<{@link CalendarError}> - */ - static create_midnight(): Time | never; - - /** - - * Returns the hour in this time - - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.Time.html#structfield.hour Rust documentation for `hour`} for more information. - */ - hour(): u8; + get ffiValue(): pointer; - /** - * Returns the minute in this time + static create(hour: number, minute: number, second: number, nanosecond: number): Time; - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.Time.html#structfield.minute Rust documentation for `minute`} for more information. - */ - minute(): u8; + static createMidnight(): Time; - /** + get hour(): number; - * Returns the second in this time + get minute(): number; - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.Time.html#structfield.second Rust documentation for `second`} for more information. - */ - second(): u8; + get second(): number; - /** + get nanosecond(): number; - * Returns the nanosecond in this time + - * See the {@link https://docs.rs/icu/latest/icu/calendar/struct.Time.html#structfield.nanosecond Rust documentation for `nanosecond`} for more information. - */ - nanosecond(): u32; -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/Time.mjs b/ffi/capi/bindings/js/Time.mjs index fc89f5460e8..dd16d093400 100644 --- a/ffi/capi/bindings/js/Time.mjs +++ b/ffi/capi/bindings/js/Time.mjs @@ -1,68 +1,121 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" -import { CalendarError_js_to_rust, CalendarError_rust_to_js } from "./CalendarError.mjs" +// generated by diplomat-tool +import { CalendarError } from "./CalendarError.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -const Time_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XTime_destroy(underlying); -}); +/** An ICU4X Time object representing a time in terms of hour, minute, second, nanosecond +* +*See the [Rust documentation for `Time`](https://docs.rs/icu/latest/icu/calendar/struct.Time.html) for more information. +*/ + +const Time_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XTime_destroy(ptr); +}); export class Time { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - Time_box_destroy_registry.register(this, underlying); + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + + constructor(ptr, selfEdge) { + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + Time_box_destroy_registry.register(this, this.#ptr); + } + + get ffiValue() { + return this.#ptr; } - } - static create(arg_hour, arg_minute, arg_second, arg_nanosecond) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XTime_create(diplomat_receive_buffer, arg_hour, arg_minute, arg_second, arg_nanosecond); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new Time(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = CalendarError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - static create_midnight() { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XTime_create_midnight(diplomat_receive_buffer); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new Time(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = CalendarError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } + static create(hour, minute, second, nanosecond) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XTime_create(diplomat_receive_buffer, hour, minute, second, nanosecond); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = CalendarError[Array.from(CalendarError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('CalendarError: ' + cause.value, { cause }); + } + return new Time(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } - hour() { - return wasm.ICU4XTime_hour(this.underlying); - } + static createMidnight() { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XTime_create_midnight(diplomat_receive_buffer); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = CalendarError[Array.from(CalendarError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('CalendarError: ' + cause.value, { cause }); + } + return new Time(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } - minute() { - return wasm.ICU4XTime_minute(this.underlying); - } + get hour() { + const result = wasm.ICU4XTime_hour(this.ffiValue); + + try { + + return result; + } finally { + + } + } + + get minute() { + const result = wasm.ICU4XTime_minute(this.ffiValue); + + try { + + return result; + } finally { + + } + } + + get second() { + const result = wasm.ICU4XTime_second(this.ffiValue); + + try { + + return result; + } finally { + + } + } + + get nanosecond() { + const result = wasm.ICU4XTime_nanosecond(this.ffiValue); + + try { + + return result; + } finally { + + } + } - second() { - return wasm.ICU4XTime_second(this.underlying); - } + - nanosecond() { - return wasm.ICU4XTime_nanosecond(this.underlying); - } -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/TimeFormatter.d.ts b/ffi/capi/bindings/js/TimeFormatter.d.ts index 0ec93e73511..7f20a7671b1 100644 --- a/ffi/capi/bindings/js/TimeFormatter.d.ts +++ b/ffi/capi/bindings/js/TimeFormatter.d.ts @@ -1,50 +1,31 @@ -import { FFIError } from "./diplomat-runtime" -import { DataProvider } from "./DataProvider"; -import { DateTime } from "./DateTime"; -import { Error } from "./Error"; -import { IsoDateTime } from "./IsoDateTime"; -import { Locale } from "./Locale"; -import { Time } from "./Time"; -import { TimeLength } from "./TimeLength"; - -/** - - * An ICU4X TimeFormatter object capable of formatting an {@link Time `Time`} type (and others) as a string - - * See the {@link https://docs.rs/icu/latest/icu/datetime/struct.TimeFormatter.html Rust documentation for `TimeFormatter`} for more information. - */ +// generated by diplomat-tool +import type { DataProvider } from "./DataProvider" +import type { DateTime } from "./DateTime" +import type { IsoDateTime } from "./IsoDateTime" +import type { Locale } from "./Locale" +import type { Time } from "./Time" +import type { TimeLength } from "./TimeLength" +import type { pointer, char } from "./diplomat-runtime.d.ts"; + + +/** An ICU4X TimeFormatter object capable of formatting an [`Time`] type (and others) as a string +* +*See the [Rust documentation for `TimeFormatter`](https://docs.rs/icu/latest/icu/datetime/struct.TimeFormatter.html) for more information. +*/ export class TimeFormatter { + - /** - - * Creates a new {@link TimeFormatter `TimeFormatter`} from locale data. - - * See the {@link https://docs.rs/icu/latest/icu/datetime/struct.TimeFormatter.html#method.try_new_with_length Rust documentation for `try_new_with_length`} for more information. - * @throws {@link FFIError}<{@link Error}> - */ - static create_with_length(provider: DataProvider, locale: Locale, length: TimeLength): TimeFormatter | never; - - /** - - * Formats a {@link Time `Time`} to a string. + get ffiValue(): pointer; - * See the {@link https://docs.rs/icu/latest/icu/datetime/struct.TimeFormatter.html#method.format Rust documentation for `format`} for more information. - */ - format_time(value: Time): string; - /** + static createWithLength(provider: DataProvider, locale: Locale, length: TimeLength): TimeFormatter; - * Formats a {@link DateTime `DateTime`} to a string. + formatTime(value: Time): string; - * See the {@link https://docs.rs/icu/latest/icu/datetime/struct.TimeFormatter.html#method.format Rust documentation for `format`} for more information. - */ - format_datetime(value: DateTime): string; + formatDatetime(value: DateTime): string; - /** + formatIsoDatetime(value: IsoDateTime): string; - * Formats a {@link IsoDateTime `IsoDateTime`} to a string. + - * See the {@link https://docs.rs/icu/latest/icu/datetime/struct.TimeFormatter.html#method.format Rust documentation for `format`} for more information. - */ - format_iso_datetime(value: IsoDateTime): string; -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/TimeFormatter.mjs b/ffi/capi/bindings/js/TimeFormatter.mjs index b8a1171dc54..5f9ede4723b 100644 --- a/ffi/capi/bindings/js/TimeFormatter.mjs +++ b/ffi/capi/bindings/js/TimeFormatter.mjs @@ -1,54 +1,109 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" -import { Error_js_to_rust, Error_rust_to_js } from "./Error.mjs" -import { TimeLength_js_to_rust, TimeLength_rust_to_js } from "./TimeLength.mjs" +// generated by diplomat-tool +import { DataProvider } from "./DataProvider.mjs" +import { DateTime } from "./DateTime.mjs" +import { Error } from "./Error.mjs" +import { IsoDateTime } from "./IsoDateTime.mjs" +import { Locale } from "./Locale.mjs" +import { Time } from "./Time.mjs" +import { TimeLength } from "./TimeLength.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -const TimeFormatter_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XTimeFormatter_destroy(underlying); -}); +/** An ICU4X TimeFormatter object capable of formatting an [`Time`] type (and others) as a string +* +*See the [Rust documentation for `TimeFormatter`](https://docs.rs/icu/latest/icu/datetime/struct.TimeFormatter.html) for more information. +*/ + +const TimeFormatter_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XTimeFormatter_destroy(ptr); +}); export class TimeFormatter { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - TimeFormatter_box_destroy_registry.register(this, underlying); + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + + constructor(ptr, selfEdge) { + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + TimeFormatter_box_destroy_registry.register(this, this.#ptr); + } + + get ffiValue() { + return this.#ptr; + } + + + static createWithLength(provider, locale, length) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XTimeFormatter_create_with_length(diplomat_receive_buffer, provider.ffiValue, locale.ffiValue, length.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = (() => {for (let i of Error.values) { if(i[1] === diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)) return Error[i[0]]; } return null;})(); + throw new Error('Error: ' + cause.value, { cause }); + } + return new TimeFormatter(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } } - } - - static create_with_length(arg_provider, arg_locale, arg_length) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XTimeFormatter_create_with_length(diplomat_receive_buffer, arg_provider.underlying, arg_locale.underlying, TimeLength_js_to_rust[arg_length]); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new TimeFormatter(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = Error_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - format_time(arg_value) { - return diplomatRuntime.withDiplomatWrite(wasm, (write) => { - return wasm.ICU4XTimeFormatter_format_time(this.underlying, arg_value.underlying, write); - }); - } - - format_datetime(arg_value) { - return diplomatRuntime.withDiplomatWrite(wasm, (write) => { - return wasm.ICU4XTimeFormatter_format_datetime(this.underlying, arg_value.underlying, write); - }); - } - - format_iso_datetime(arg_value) { - return diplomatRuntime.withDiplomatWrite(wasm, (write) => { - return wasm.ICU4XTimeFormatter_format_iso_datetime(this.underlying, arg_value.underlying, write); - }); - } -} + + formatTime(value) { + + const write = wasm.diplomat_buffer_write_create(0); + wasm.ICU4XTimeFormatter_format_time(this.ffiValue, value.ffiValue, write); + + try { + + return diplomatRuntime.readString8(wasm, wasm.diplomat_buffer_write_get_bytes(write), wasm.diplomat_buffer_write_len(write)); + } finally { + + wasm.diplomat_buffer_write_destroy(write); + + } + } + + formatDatetime(value) { + + const write = wasm.diplomat_buffer_write_create(0); + wasm.ICU4XTimeFormatter_format_datetime(this.ffiValue, value.ffiValue, write); + + try { + + return diplomatRuntime.readString8(wasm, wasm.diplomat_buffer_write_get_bytes(write), wasm.diplomat_buffer_write_len(write)); + } finally { + + wasm.diplomat_buffer_write_destroy(write); + + } + } + + formatIsoDatetime(value) { + + const write = wasm.diplomat_buffer_write_create(0); + wasm.ICU4XTimeFormatter_format_iso_datetime(this.ffiValue, value.ffiValue, write); + + try { + + return diplomatRuntime.readString8(wasm, wasm.diplomat_buffer_write_get_bytes(write), wasm.diplomat_buffer_write_len(write)); + } finally { + + wasm.diplomat_buffer_write_destroy(write); + + } + } + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/TimeLength.d.ts b/ffi/capi/bindings/js/TimeLength.d.ts index fd865840b92..e32cff4f580 100644 --- a/ffi/capi/bindings/js/TimeLength.d.ts +++ b/ffi/capi/bindings/js/TimeLength.d.ts @@ -1,19 +1,25 @@ +// generated by diplomat-tool +import type { pointer, char } from "./diplomat-runtime.d.ts"; + +// Base enumerator definition +/** See the [Rust documentation for `Time`](https://docs.rs/icu/latest/icu/datetime/options/length/enum.Time.html) for more information. +*/ +export class TimeLength { + constructor(value : TimeLength | string); + + get value() : string; + + get ffiValue() : number; + + static Full : TimeLength; + + static Long : TimeLength; + + static Medium : TimeLength; + + static Short : TimeLength; + + + -/** - - * See the {@link https://docs.rs/icu/latest/icu/datetime/options/length/enum.Time.html Rust documentation for `Time`} for more information. - */ -export enum TimeLength { - /** - */ - Full = 'Full', - /** - */ - Long = 'Long', - /** - */ - Medium = 'Medium', - /** - */ - Short = 'Short', } \ No newline at end of file diff --git a/ffi/capi/bindings/js/TimeLength.mjs b/ffi/capi/bindings/js/TimeLength.mjs index 178c73a52a2..21b54efb631 100644 --- a/ffi/capi/bindings/js/TimeLength.mjs +++ b/ffi/capi/bindings/js/TimeLength.mjs @@ -1,23 +1,50 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" - -export const TimeLength_js_to_rust = { - "Full": 0, - "Long": 1, - "Medium": 2, - "Short": 3, -}; - -export const TimeLength_rust_to_js = { - [0]: "Full", - [1]: "Long", - [2]: "Medium", - [3]: "Short", -}; - -export const TimeLength = { - "Full": "Full", - "Long": "Long", - "Medium": "Medium", - "Short": "Short", -}; +// generated by diplomat-tool +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; + +// Base enumerator definition +/** See the [Rust documentation for `Time`](https://docs.rs/icu/latest/icu/datetime/options/length/enum.Time.html) for more information. +*/ +export class TimeLength { + #value = undefined; + + static values = new Map([ + ["Full", 0], + ["Long", 1], + ["Medium", 2], + ["Short", 3] + ]); + constructor(value) { + if (value instanceof TimeLength) { + this.#value = value.value; + return; + } + + if (TimeLength.values.has(value)) { + this.#value = value; + return; + } + + throw TypeError(value + " is not a TimeLength and does not correspond to any of its enumerator values."); + } + + get value() { + return this.#value; + } + + get ffiValue() { + return TimeLength.values.get(this.#value); + } + + static Full = new TimeLength("Full"); + + static Long = new TimeLength("Long"); + + static Medium = new TimeLength("Medium"); + + static Short = new TimeLength("Short"); + + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/TimeZoneFormatter.d.ts b/ffi/capi/bindings/js/TimeZoneFormatter.d.ts index 9fdcdbb83b6..2c587a45b6d 100644 --- a/ffi/capi/bindings/js/TimeZoneFormatter.d.ts +++ b/ffi/capi/bindings/js/TimeZoneFormatter.d.ts @@ -1,123 +1,43 @@ -import { FFIError } from "./diplomat-runtime" -import { CustomTimeZone } from "./CustomTimeZone"; -import { DataProvider } from "./DataProvider"; -import { Error } from "./Error"; -import { IsoTimeZoneOptions } from "./IsoTimeZoneOptions"; -import { Locale } from "./Locale"; - -/** - - * An ICU4X TimeZoneFormatter object capable of formatting an {@link CustomTimeZone `CustomTimeZone`} type (and others) as a string - - * See the {@link https://docs.rs/icu/latest/icu/datetime/time_zone/struct.TimeZoneFormatter.html Rust documentation for `TimeZoneFormatter`} for more information. - */ +// generated by diplomat-tool +import type { CustomTimeZone } from "./CustomTimeZone" +import type { DataProvider } from "./DataProvider" +import type { IsoTimeZoneOptions } from "./IsoTimeZoneOptions" +import type { Locale } from "./Locale" +import type { pointer, char } from "./diplomat-runtime.d.ts"; + + +/** An ICU4X TimeZoneFormatter object capable of formatting an [`CustomTimeZone`] type (and others) as a string +* +*See the [Rust documentation for `TimeZoneFormatter`](https://docs.rs/icu/latest/icu/datetime/time_zone/struct.TimeZoneFormatter.html) for more information. +*/ export class TimeZoneFormatter { + - /** - - * Creates a new {@link TimeZoneFormatter `TimeZoneFormatter`} from locale data. - - * Uses localized GMT as the fallback format. - - * See the {@link https://docs.rs/icu/latest/icu/datetime/time_zone/struct.TimeZoneFormatter.html#method.try_new Rust documentation for `try_new`} for more information. - - * Additional information: {@link https://docs.rs/icu/latest/icu/datetime/time_zone/enum.FallbackFormat.html 1} - * @throws {@link FFIError}<{@link Error}> - */ - static create_with_localized_gmt_fallback(provider: DataProvider, locale: Locale): TimeZoneFormatter | never; - - /** - - * Creates a new {@link TimeZoneFormatter `TimeZoneFormatter`} from locale data. - - * Uses ISO-8601 as the fallback format. - - * See the {@link https://docs.rs/icu/latest/icu/datetime/time_zone/struct.TimeZoneFormatter.html#method.try_new Rust documentation for `try_new`} for more information. - - * Additional information: {@link https://docs.rs/icu/latest/icu/datetime/time_zone/enum.FallbackFormat.html 1} - * @throws {@link FFIError}<{@link Error}> - */ - static create_with_iso_8601_fallback(provider: DataProvider, locale: Locale, options: IsoTimeZoneOptions): TimeZoneFormatter | never; - - /** - - * Loads generic non-location long format. Example: "Pacific Time" - - * See the {@link https://docs.rs/icu/latest/icu/datetime/time_zone/struct.TimeZoneFormatter.html#method.include_generic_non_location_long Rust documentation for `include_generic_non_location_long`} for more information. - * @throws {@link FFIError}<{@link Error}> - */ - load_generic_non_location_long(provider: DataProvider): void | never; - - /** - - * Loads generic non-location short format. Example: "PT" - - * See the {@link https://docs.rs/icu/latest/icu/datetime/time_zone/struct.TimeZoneFormatter.html#method.include_generic_non_location_short Rust documentation for `include_generic_non_location_short`} for more information. - * @throws {@link FFIError}<{@link Error}> - */ - load_generic_non_location_short(provider: DataProvider): void | never; - - /** - - * Loads specific non-location long format. Example: "Pacific Standard Time" - - * See the {@link https://docs.rs/icu/latest/icu/datetime/time_zone/struct.TimeZoneFormatter.html#method.include_specific_non_location_long Rust documentation for `include_specific_non_location_long`} for more information. - * @throws {@link FFIError}<{@link Error}> - */ - load_specific_non_location_long(provider: DataProvider): void | never; - - /** - - * Loads specific non-location short format. Example: "PST" - - * See the {@link https://docs.rs/icu/latest/icu/datetime/time_zone/struct.TimeZoneFormatter.html#method.include_specific_non_location_short Rust documentation for `include_specific_non_location_short`} for more information. - * @throws {@link FFIError}<{@link Error}> - */ - load_specific_non_location_short(provider: DataProvider): void | never; - - /** - - * Loads generic location format. Example: "Los Angeles Time" + get ffiValue(): pointer; - * See the {@link https://docs.rs/icu/latest/icu/datetime/time_zone/struct.TimeZoneFormatter.html#method.include_generic_location_format Rust documentation for `include_generic_location_format`} for more information. - * @throws {@link FFIError}<{@link Error}> - */ - load_generic_location_format(provider: DataProvider): void | never; - /** + static createWithLocalizedGmtFallback(provider: DataProvider, locale: Locale): TimeZoneFormatter; - * Loads localized GMT format. Example: "GMT-07:00" + static createWithIso8601Fallback(provider: DataProvider, locale: Locale, options: IsoTimeZoneOptions): TimeZoneFormatter; - * See the {@link https://docs.rs/icu/latest/icu/datetime/time_zone/struct.TimeZoneFormatter.html#method.include_localized_gmt_format Rust documentation for `include_localized_gmt_format`} for more information. - * @throws {@link FFIError}<{@link Error}> - */ - include_localized_gmt_format(): void | never; + loadGenericNonLocationLong(provider: DataProvider): void; - /** + loadGenericNonLocationShort(provider: DataProvider): void; - * Loads ISO-8601 format. Example: "-07:00" + loadSpecificNonLocationLong(provider: DataProvider): void; - * See the {@link https://docs.rs/icu/latest/icu/datetime/time_zone/struct.TimeZoneFormatter.html#method.include_iso_8601_format Rust documentation for `include_iso_8601_format`} for more information. - * @throws {@link FFIError}<{@link Error}> - */ - load_iso_8601_format(options: IsoTimeZoneOptions): void | never; + loadSpecificNonLocationShort(provider: DataProvider): void; - /** + loadGenericLocationFormat(provider: DataProvider): void; - * Formats a {@link CustomTimeZone `CustomTimeZone`} to a string. + includeLocalizedGmtFormat(): void; - * See the {@link https://docs.rs/icu/latest/icu/datetime/time_zone/struct.TimeZoneFormatter.html#method.format Rust documentation for `format`} for more information. + loadIso8601Format(options: IsoTimeZoneOptions): void; - * See the {@link https://docs.rs/icu/latest/icu/datetime/time_zone/struct.TimeZoneFormatter.html#method.format_to_string Rust documentation for `format_to_string`} for more information. - */ - format_custom_time_zone(value: CustomTimeZone): string; + formatCustomTimeZone(value: CustomTimeZone): string; - /** + formatCustomTimeZoneNoFallback(value: CustomTimeZone): string; - * Formats a {@link CustomTimeZone `CustomTimeZone`} to a string, performing no fallback + - * See the {@link https://docs.rs/icu/latest/icu/datetime/struct.FormattedTimeZone.html#method.write_no_fallback Rust documentation for `write_no_fallback`} for more information. - * @throws {@link FFIError}<{@link Error}> - */ - format_custom_time_zone_no_fallback(value: CustomTimeZone): string | never; -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/TimeZoneFormatter.mjs b/ffi/capi/bindings/js/TimeZoneFormatter.mjs index c90d55d6644..2c3f6009124 100644 --- a/ffi/capi/bindings/js/TimeZoneFormatter.mjs +++ b/ffi/capi/bindings/js/TimeZoneFormatter.mjs @@ -1,205 +1,264 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" -import { Error_js_to_rust, Error_rust_to_js } from "./Error.mjs" -import { IsoTimeZoneFormat_js_to_rust, IsoTimeZoneFormat_rust_to_js } from "./IsoTimeZoneFormat.mjs" -import { IsoTimeZoneMinuteDisplay_js_to_rust, IsoTimeZoneMinuteDisplay_rust_to_js } from "./IsoTimeZoneMinuteDisplay.mjs" -import { IsoTimeZoneSecondDisplay_js_to_rust, IsoTimeZoneSecondDisplay_rust_to_js } from "./IsoTimeZoneSecondDisplay.mjs" - -const TimeZoneFormatter_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XTimeZoneFormatter_destroy(underlying); -}); +// generated by diplomat-tool +import { CustomTimeZone } from "./CustomTimeZone.mjs" +import { DataProvider } from "./DataProvider.mjs" +import { Error } from "./Error.mjs" +import { IsoTimeZoneOptions } from "./IsoTimeZoneOptions.mjs" +import { Locale } from "./Locale.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; + +/** An ICU4X TimeZoneFormatter object capable of formatting an [`CustomTimeZone`] type (and others) as a string +* +*See the [Rust documentation for `TimeZoneFormatter`](https://docs.rs/icu/latest/icu/datetime/time_zone/struct.TimeZoneFormatter.html) for more information. +*/ + +const TimeZoneFormatter_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XTimeZoneFormatter_destroy(ptr); +}); export class TimeZoneFormatter { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - TimeZoneFormatter_box_destroy_registry.register(this, underlying); + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + + constructor(ptr, selfEdge) { + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + TimeZoneFormatter_box_destroy_registry.register(this, this.#ptr); + } + + get ffiValue() { + return this.#ptr; + } + + + static createWithLocalizedGmtFallback(provider, locale) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XTimeZoneFormatter_create_with_localized_gmt_fallback(diplomat_receive_buffer, provider.ffiValue, locale.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = (() => {for (let i of Error.values) { if(i[1] === diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)) return Error[i[0]]; } return null;})(); + throw new Error('Error: ' + cause.value, { cause }); + } + return new TimeZoneFormatter(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static createWithIso8601Fallback(provider, locale, options) { + + let slice_cleanup_callbacks = []; + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XTimeZoneFormatter_create_with_iso_8601_fallback(diplomat_receive_buffer, provider.ffiValue, locale.ffiValue, ...options._intoFFI(slice_cleanup_callbacks, {})); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = (() => {for (let i of Error.values) { if(i[1] === diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)) return Error[i[0]]; } return null;})(); + throw new Error('Error: ' + cause.value, { cause }); + } + return new TimeZoneFormatter(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + for (let cleanup of slice_cleanup_callbacks) { + cleanup(); + } + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } } - } - - static create_with_localized_gmt_fallback(arg_provider, arg_locale) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XTimeZoneFormatter_create_with_localized_gmt_fallback(diplomat_receive_buffer, arg_provider.underlying, arg_locale.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new TimeZoneFormatter(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = Error_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static create_with_iso_8601_fallback(arg_provider, arg_locale, arg_options) { - const field_format_arg_options = arg_options["format"]; - const field_minutes_arg_options = arg_options["minutes"]; - const field_seconds_arg_options = arg_options["seconds"]; - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XTimeZoneFormatter_create_with_iso_8601_fallback(diplomat_receive_buffer, arg_provider.underlying, arg_locale.underlying, IsoTimeZoneFormat_js_to_rust[field_format_arg_options], IsoTimeZoneMinuteDisplay_js_to_rust[field_minutes_arg_options], IsoTimeZoneSecondDisplay_js_to_rust[field_seconds_arg_options]); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new TimeZoneFormatter(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = Error_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - load_generic_non_location_long(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XTimeZoneFormatter_load_generic_non_location_long(diplomat_receive_buffer, this.underlying, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = {}; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = Error_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - load_generic_non_location_short(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XTimeZoneFormatter_load_generic_non_location_short(diplomat_receive_buffer, this.underlying, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = {}; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = Error_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - load_specific_non_location_long(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XTimeZoneFormatter_load_specific_non_location_long(diplomat_receive_buffer, this.underlying, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = {}; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = Error_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - load_specific_non_location_short(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XTimeZoneFormatter_load_specific_non_location_short(diplomat_receive_buffer, this.underlying, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = {}; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = Error_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - load_generic_location_format(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XTimeZoneFormatter_load_generic_location_format(diplomat_receive_buffer, this.underlying, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = {}; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = Error_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - include_localized_gmt_format() { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XTimeZoneFormatter_include_localized_gmt_format(diplomat_receive_buffer, this.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = {}; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = Error_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - load_iso_8601_format(arg_options) { - const field_format_arg_options = arg_options["format"]; - const field_minutes_arg_options = arg_options["minutes"]; - const field_seconds_arg_options = arg_options["seconds"]; - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XTimeZoneFormatter_load_iso_8601_format(diplomat_receive_buffer, this.underlying, IsoTimeZoneFormat_js_to_rust[field_format_arg_options], IsoTimeZoneMinuteDisplay_js_to_rust[field_minutes_arg_options], IsoTimeZoneSecondDisplay_js_to_rust[field_seconds_arg_options]); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = {}; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = Error_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - format_custom_time_zone(arg_value) { - return diplomatRuntime.withDiplomatWrite(wasm, (write) => { - return wasm.ICU4XTimeZoneFormatter_format_custom_time_zone(this.underlying, arg_value.underlying, write); - }); - } - - format_custom_time_zone_no_fallback(arg_value) { - return diplomatRuntime.withDiplomatWrite(wasm, (write) => { - return (() => { + + loadGenericNonLocationLong(provider) { + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XTimeZoneFormatter_format_custom_time_zone_no_fallback(diplomat_receive_buffer, this.underlying, arg_value.underlying, write); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = {}; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = Error_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); + const result = wasm.ICU4XTimeZoneFormatter_load_generic_non_location_long(diplomat_receive_buffer, this.ffiValue, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = (() => {for (let i of Error.values) { if(i[1] === diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)) return Error[i[0]]; } return null;})(); + throw new Error('Error: ' + cause.value, { cause }); + } + + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + } - })(); - }); - } -} + } + + loadGenericNonLocationShort(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XTimeZoneFormatter_load_generic_non_location_short(diplomat_receive_buffer, this.ffiValue, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = (() => {for (let i of Error.values) { if(i[1] === diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)) return Error[i[0]]; } return null;})(); + throw new Error('Error: ' + cause.value, { cause }); + } + + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + loadSpecificNonLocationLong(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XTimeZoneFormatter_load_specific_non_location_long(diplomat_receive_buffer, this.ffiValue, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = (() => {for (let i of Error.values) { if(i[1] === diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)) return Error[i[0]]; } return null;})(); + throw new Error('Error: ' + cause.value, { cause }); + } + + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + loadSpecificNonLocationShort(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XTimeZoneFormatter_load_specific_non_location_short(diplomat_receive_buffer, this.ffiValue, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = (() => {for (let i of Error.values) { if(i[1] === diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)) return Error[i[0]]; } return null;})(); + throw new Error('Error: ' + cause.value, { cause }); + } + + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + loadGenericLocationFormat(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XTimeZoneFormatter_load_generic_location_format(diplomat_receive_buffer, this.ffiValue, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = (() => {for (let i of Error.values) { if(i[1] === diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)) return Error[i[0]]; } return null;})(); + throw new Error('Error: ' + cause.value, { cause }); + } + + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + includeLocalizedGmtFormat() { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XTimeZoneFormatter_include_localized_gmt_format(diplomat_receive_buffer, this.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = (() => {for (let i of Error.values) { if(i[1] === diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)) return Error[i[0]]; } return null;})(); + throw new Error('Error: ' + cause.value, { cause }); + } + + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + loadIso8601Format(options) { + + let slice_cleanup_callbacks = []; + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XTimeZoneFormatter_load_iso_8601_format(diplomat_receive_buffer, this.ffiValue, ...options._intoFFI(slice_cleanup_callbacks, {})); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = (() => {for (let i of Error.values) { if(i[1] === diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)) return Error[i[0]]; } return null;})(); + throw new Error('Error: ' + cause.value, { cause }); + } + + } finally { + + for (let cleanup of slice_cleanup_callbacks) { + cleanup(); + } + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + formatCustomTimeZone(value) { + + const write = wasm.diplomat_buffer_write_create(0); + wasm.ICU4XTimeZoneFormatter_format_custom_time_zone(this.ffiValue, value.ffiValue, write); + + try { + + return diplomatRuntime.readString8(wasm, wasm.diplomat_buffer_write_get_bytes(write), wasm.diplomat_buffer_write_len(write)); + } finally { + + wasm.diplomat_buffer_write_destroy(write); + + } + } + + formatCustomTimeZoneNoFallback(value) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + + const write = wasm.diplomat_buffer_write_create(0); + const result = wasm.ICU4XTimeZoneFormatter_format_custom_time_zone_no_fallback(diplomat_receive_buffer, this.ffiValue, value.ffiValue, write); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = (() => {for (let i of Error.values) { if(i[1] === diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)) return Error[i[0]]; } return null;})(); + throw new Error('Error: ' + cause.value, { cause }); + } + return diplomatRuntime.readString8(wasm, wasm.diplomat_buffer_write_get_bytes(write), wasm.diplomat_buffer_write_len(write)); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + wasm.diplomat_buffer_write_destroy(write); + + } + } + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/TimeZoneIdMapper.d.ts b/ffi/capi/bindings/js/TimeZoneIdMapper.d.ts index 0ac2ced5ff0..a1d0522f0b7 100644 --- a/ffi/capi/bindings/js/TimeZoneIdMapper.d.ts +++ b/ffi/capi/bindings/js/TimeZoneIdMapper.d.ts @@ -1,50 +1,31 @@ -import { FFIError } from "./diplomat-runtime" -import { DataError } from "./DataError"; -import { DataProvider } from "./DataProvider"; -import { TimeZoneInvalidIdError } from "./TimeZoneInvalidIdError"; - -/** - - * A mapper between IANA time zone identifiers and BCP-47 time zone identifiers. - - * This mapper supports two-way mapping, but it is optimized for the case of IANA to BCP-47. It also supports normalizing and canonicalizing the IANA strings. - - * See the {@link https://docs.rs/icu/latest/icu/timezone/struct.TimeZoneIdMapper.html Rust documentation for `TimeZoneIdMapper`} for more information. - */ +// generated by diplomat-tool +import type { DataProvider } from "./DataProvider" +import type { pointer, char } from "./diplomat-runtime.d.ts"; + + +/** A mapper between IANA time zone identifiers and BCP-47 time zone identifiers. +* +*This mapper supports two-way mapping, but it is optimized for the case of IANA to BCP-47. +*It also supports normalizing and canonicalizing the IANA strings. +* +*See the [Rust documentation for `TimeZoneIdMapper`](https://docs.rs/icu/latest/icu/timezone/struct.TimeZoneIdMapper.html) for more information. +*/ export class TimeZoneIdMapper { + - /** - - * See the {@link https://docs.rs/icu/latest/icu/timezone/struct.TimeZoneIdMapper.html#method.new Rust documentation for `new`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static create(provider: DataProvider): TimeZoneIdMapper | never; + get ffiValue(): pointer; - /** - * See the {@link https://docs.rs/icu/latest/icu/timezone/struct.TimeZoneIdMapperBorrowed.html#method.iana_to_bcp47 Rust documentation for `iana_to_bcp47`} for more information. - * @throws {@link FFIError}<{@link TimeZoneInvalidIdError}> - */ - iana_to_bcp47(value: string): string | never; + static create(provider: DataProvider): TimeZoneIdMapper; - /** + ianaToBcp47(value: string): string; - * See the {@link https://docs.rs/icu/latest/icu/timezone/struct.TimeZoneIdMapperBorrowed.html#method.normalize_iana Rust documentation for `normalize_iana`} for more information. - * @throws {@link FFIError}<{@link TimeZoneInvalidIdError}> - */ - normalize_iana(value: string): string | never; + normalizeIana(value: string): string; - /** + canonicalizeIana(value: string): string; - * See the {@link https://docs.rs/icu/latest/icu/timezone/struct.TimeZoneIdMapperBorrowed.html#method.canonicalize_iana Rust documentation for `canonicalize_iana`} for more information. - * @throws {@link FFIError}<{@link TimeZoneInvalidIdError}> - */ - canonicalize_iana(value: string): string | never; + findCanonicalIanaFromBcp47(value: string): string; - /** + - * See the {@link https://docs.rs/icu/latest/icu/timezone/struct.TimeZoneIdMapperBorrowed.html#method.find_canonical_iana_from_bcp47 Rust documentation for `find_canonical_iana_from_bcp47`} for more information. - * @throws {@link FFIError}<{@link TimeZoneInvalidIdError}> - */ - find_canonical_iana_from_bcp47(value: string): string | never; -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/TimeZoneIdMapper.mjs b/ffi/capi/bindings/js/TimeZoneIdMapper.mjs index 918aac6b274..4e045a834c4 100644 --- a/ffi/capi/bindings/js/TimeZoneIdMapper.mjs +++ b/ffi/capi/bindings/js/TimeZoneIdMapper.mjs @@ -1,124 +1,171 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" -import { DataError_js_to_rust, DataError_rust_to_js } from "./DataError.mjs" -import { TimeZoneInvalidIdError_js_to_rust, TimeZoneInvalidIdError_rust_to_js } from "./TimeZoneInvalidIdError.mjs" +// generated by diplomat-tool +import { DataError } from "./DataError.mjs" +import { DataProvider } from "./DataProvider.mjs" +import { TimeZoneInvalidIdError } from "./TimeZoneInvalidIdError.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -const TimeZoneIdMapper_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XTimeZoneIdMapper_destroy(underlying); -}); +/** A mapper between IANA time zone identifiers and BCP-47 time zone identifiers. +* +*This mapper supports two-way mapping, but it is optimized for the case of IANA to BCP-47. +*It also supports normalizing and canonicalizing the IANA strings. +* +*See the [Rust documentation for `TimeZoneIdMapper`](https://docs.rs/icu/latest/icu/timezone/struct.TimeZoneIdMapper.html) for more information. +*/ + +const TimeZoneIdMapper_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XTimeZoneIdMapper_destroy(ptr); +}); export class TimeZoneIdMapper { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - TimeZoneIdMapper_box_destroy_registry.register(this, underlying); + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + + constructor(ptr, selfEdge) { + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + TimeZoneIdMapper_box_destroy_registry.register(this, this.#ptr); } - } - static create(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XTimeZoneIdMapper_create(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new TimeZoneIdMapper(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } + get ffiValue() { + return this.#ptr; + } + + + static create(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XTimeZoneIdMapper_create(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new TimeZoneIdMapper(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } - iana_to_bcp47(arg_value) { - const buf_arg_value = diplomatRuntime.DiplomatBuf.str8(wasm, arg_value); - const diplomat_out = diplomatRuntime.withDiplomatWrite(wasm, (write) => { - return (() => { + ianaToBcp47(value) { + + const valueSlice = diplomatRuntime.DiplomatBuf.str8(wasm, value); + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XTimeZoneIdMapper_iana_to_bcp47(diplomat_receive_buffer, this.underlying, buf_arg_value.ptr, buf_arg_value.size, write); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = {}; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = TimeZoneInvalidIdError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); + + const write = wasm.diplomat_buffer_write_create(0); + const result = wasm.ICU4XTimeZoneIdMapper_iana_to_bcp47(diplomat_receive_buffer, this.ffiValue, valueSlice.ptr, valueSlice.size, write); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = TimeZoneInvalidIdError[Array.from(TimeZoneInvalidIdError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('TimeZoneInvalidIdError: ' + cause.value, { cause }); + } + return diplomatRuntime.readString8(wasm, wasm.diplomat_buffer_write_get_bytes(write), wasm.diplomat_buffer_write_len(write)); + } finally { + + valueSlice.free(); + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + wasm.diplomat_buffer_write_destroy(write); + } - })(); - }); - buf_arg_value.free(); - return diplomat_out; - } + } - normalize_iana(arg_value) { - const buf_arg_value = diplomatRuntime.DiplomatBuf.str8(wasm, arg_value); - const diplomat_out = diplomatRuntime.withDiplomatWrite(wasm, (write) => { - return (() => { + normalizeIana(value) { + + const valueSlice = diplomatRuntime.DiplomatBuf.str8(wasm, value); + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XTimeZoneIdMapper_normalize_iana(diplomat_receive_buffer, this.underlying, buf_arg_value.ptr, buf_arg_value.size, write); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = {}; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = TimeZoneInvalidIdError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); + + const write = wasm.diplomat_buffer_write_create(0); + const result = wasm.ICU4XTimeZoneIdMapper_normalize_iana(diplomat_receive_buffer, this.ffiValue, valueSlice.ptr, valueSlice.size, write); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = TimeZoneInvalidIdError[Array.from(TimeZoneInvalidIdError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('TimeZoneInvalidIdError: ' + cause.value, { cause }); + } + return diplomatRuntime.readString8(wasm, wasm.diplomat_buffer_write_get_bytes(write), wasm.diplomat_buffer_write_len(write)); + } finally { + + valueSlice.free(); + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + wasm.diplomat_buffer_write_destroy(write); + } - })(); - }); - buf_arg_value.free(); - return diplomat_out; - } + } - canonicalize_iana(arg_value) { - const buf_arg_value = diplomatRuntime.DiplomatBuf.str8(wasm, arg_value); - const diplomat_out = diplomatRuntime.withDiplomatWrite(wasm, (write) => { - return (() => { + canonicalizeIana(value) { + + const valueSlice = diplomatRuntime.DiplomatBuf.str8(wasm, value); + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XTimeZoneIdMapper_canonicalize_iana(diplomat_receive_buffer, this.underlying, buf_arg_value.ptr, buf_arg_value.size, write); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = {}; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = TimeZoneInvalidIdError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); + + const write = wasm.diplomat_buffer_write_create(0); + const result = wasm.ICU4XTimeZoneIdMapper_canonicalize_iana(diplomat_receive_buffer, this.ffiValue, valueSlice.ptr, valueSlice.size, write); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = TimeZoneInvalidIdError[Array.from(TimeZoneInvalidIdError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('TimeZoneInvalidIdError: ' + cause.value, { cause }); + } + return diplomatRuntime.readString8(wasm, wasm.diplomat_buffer_write_get_bytes(write), wasm.diplomat_buffer_write_len(write)); + } finally { + + valueSlice.free(); + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + wasm.diplomat_buffer_write_destroy(write); + } - })(); - }); - buf_arg_value.free(); - return diplomat_out; - } + } - find_canonical_iana_from_bcp47(arg_value) { - const buf_arg_value = diplomatRuntime.DiplomatBuf.str8(wasm, arg_value); - const diplomat_out = diplomatRuntime.withDiplomatWrite(wasm, (write) => { - return (() => { + findCanonicalIanaFromBcp47(value) { + + const valueSlice = diplomatRuntime.DiplomatBuf.str8(wasm, value); + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XTimeZoneIdMapper_find_canonical_iana_from_bcp47(diplomat_receive_buffer, this.underlying, buf_arg_value.ptr, buf_arg_value.size, write); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = {}; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = TimeZoneInvalidIdError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); + + const write = wasm.diplomat_buffer_write_create(0); + const result = wasm.ICU4XTimeZoneIdMapper_find_canonical_iana_from_bcp47(diplomat_receive_buffer, this.ffiValue, valueSlice.ptr, valueSlice.size, write); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = TimeZoneInvalidIdError[Array.from(TimeZoneInvalidIdError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('TimeZoneInvalidIdError: ' + cause.value, { cause }); + } + return diplomatRuntime.readString8(wasm, wasm.diplomat_buffer_write_get_bytes(write), wasm.diplomat_buffer_write_len(write)); + } finally { + + valueSlice.free(); + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + wasm.diplomat_buffer_write_destroy(write); + } - })(); - }); - buf_arg_value.free(); - return diplomat_out; - } -} + } + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/TimeZoneIdMapperWithFastCanonicalization.d.ts b/ffi/capi/bindings/js/TimeZoneIdMapperWithFastCanonicalization.d.ts index 97846421ac1..c2651baebf3 100644 --- a/ffi/capi/bindings/js/TimeZoneIdMapperWithFastCanonicalization.d.ts +++ b/ffi/capi/bindings/js/TimeZoneIdMapperWithFastCanonicalization.d.ts @@ -1,36 +1,27 @@ -import { FFIError } from "./diplomat-runtime" -import { DataError } from "./DataError"; -import { DataProvider } from "./DataProvider"; -import { TimeZoneInvalidIdError } from "./TimeZoneInvalidIdError"; - -/** - - * A mapper between IANA time zone identifiers and BCP-47 time zone identifiers. - - * This mapper supports two-way mapping, but it is optimized for the case of IANA to BCP-47. It also supports normalizing and canonicalizing the IANA strings. - - * See the {@link https://docs.rs/icu/latest/icu/timezone/struct.TimeZoneIdMapperWithFastCanonicalization.html Rust documentation for `TimeZoneIdMapperWithFastCanonicalization`} for more information. - */ +// generated by diplomat-tool +import type { DataProvider } from "./DataProvider" +import type { pointer, char } from "./diplomat-runtime.d.ts"; + + +/** A mapper between IANA time zone identifiers and BCP-47 time zone identifiers. +* +*This mapper supports two-way mapping, but it is optimized for the case of IANA to BCP-47. +*It also supports normalizing and canonicalizing the IANA strings. +* +*See the [Rust documentation for `TimeZoneIdMapperWithFastCanonicalization`](https://docs.rs/icu/latest/icu/timezone/struct.TimeZoneIdMapperWithFastCanonicalization.html) for more information. +*/ export class TimeZoneIdMapperWithFastCanonicalization { + + + get ffiValue(): pointer; - /** - * See the {@link https://docs.rs/icu/latest/icu/timezone/struct.TimeZoneIdMapperWithFastCanonicalization.html#method.new Rust documentation for `new`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static create(provider: DataProvider): TimeZoneIdMapperWithFastCanonicalization | never; + static create(provider: DataProvider): TimeZoneIdMapperWithFastCanonicalization; - /** + canonicalizeIana(value: string): string; - * See the {@link https://docs.rs/icu/latest/icu/timezone/struct.TimeZoneIdMapperWithFastCanonicalizationBorrowed.html#method.canonicalize_iana Rust documentation for `canonicalize_iana`} for more information. - * @throws {@link FFIError}<{@link TimeZoneInvalidIdError}> - */ - canonicalize_iana(value: string): string | never; + canonicalIanaFromBcp47(value: string): string; - /** + - * See the {@link https://docs.rs/icu/latest/icu/timezone/struct.TimeZoneIdMapperWithFastCanonicalizationBorrowed.html#method.canonical_iana_from_bcp47 Rust documentation for `canonical_iana_from_bcp47`} for more information. - * @throws {@link FFIError}<{@link TimeZoneInvalidIdError}> - */ - canonical_iana_from_bcp47(value: string): string | never; -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/TimeZoneIdMapperWithFastCanonicalization.mjs b/ffi/capi/bindings/js/TimeZoneIdMapperWithFastCanonicalization.mjs index 331d9b88c76..1e161e14af9 100644 --- a/ffi/capi/bindings/js/TimeZoneIdMapperWithFastCanonicalization.mjs +++ b/ffi/capi/bindings/js/TimeZoneIdMapperWithFastCanonicalization.mjs @@ -1,80 +1,117 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" -import { DataError_js_to_rust, DataError_rust_to_js } from "./DataError.mjs" -import { TimeZoneInvalidIdError_js_to_rust, TimeZoneInvalidIdError_rust_to_js } from "./TimeZoneInvalidIdError.mjs" +// generated by diplomat-tool +import { DataError } from "./DataError.mjs" +import { DataProvider } from "./DataProvider.mjs" +import { TimeZoneInvalidIdError } from "./TimeZoneInvalidIdError.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -const TimeZoneIdMapperWithFastCanonicalization_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XTimeZoneIdMapperWithFastCanonicalization_destroy(underlying); -}); +/** A mapper between IANA time zone identifiers and BCP-47 time zone identifiers. +* +*This mapper supports two-way mapping, but it is optimized for the case of IANA to BCP-47. +*It also supports normalizing and canonicalizing the IANA strings. +* +*See the [Rust documentation for `TimeZoneIdMapperWithFastCanonicalization`](https://docs.rs/icu/latest/icu/timezone/struct.TimeZoneIdMapperWithFastCanonicalization.html) for more information. +*/ + +const TimeZoneIdMapperWithFastCanonicalization_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XTimeZoneIdMapperWithFastCanonicalization_destroy(ptr); +}); export class TimeZoneIdMapperWithFastCanonicalization { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - TimeZoneIdMapperWithFastCanonicalization_box_destroy_registry.register(this, underlying); + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + + constructor(ptr, selfEdge) { + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + TimeZoneIdMapperWithFastCanonicalization_box_destroy_registry.register(this, this.#ptr); } - } - static create(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XTimeZoneIdMapperWithFastCanonicalization_create(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new TimeZoneIdMapperWithFastCanonicalization(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } + get ffiValue() { + return this.#ptr; + } + + + static create(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XTimeZoneIdMapperWithFastCanonicalization_create(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new TimeZoneIdMapperWithFastCanonicalization(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } - canonicalize_iana(arg_value) { - const buf_arg_value = diplomatRuntime.DiplomatBuf.str8(wasm, arg_value); - const diplomat_out = diplomatRuntime.withDiplomatWrite(wasm, (write) => { - return (() => { + canonicalizeIana(value) { + + const valueSlice = diplomatRuntime.DiplomatBuf.str8(wasm, value); + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XTimeZoneIdMapperWithFastCanonicalization_canonicalize_iana(diplomat_receive_buffer, this.underlying, buf_arg_value.ptr, buf_arg_value.size, write); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = {}; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = TimeZoneInvalidIdError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); + + const write = wasm.diplomat_buffer_write_create(0); + const result = wasm.ICU4XTimeZoneIdMapperWithFastCanonicalization_canonicalize_iana(diplomat_receive_buffer, this.ffiValue, valueSlice.ptr, valueSlice.size, write); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = TimeZoneInvalidIdError[Array.from(TimeZoneInvalidIdError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('TimeZoneInvalidIdError: ' + cause.value, { cause }); + } + return diplomatRuntime.readString8(wasm, wasm.diplomat_buffer_write_get_bytes(write), wasm.diplomat_buffer_write_len(write)); + } finally { + + valueSlice.free(); + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + wasm.diplomat_buffer_write_destroy(write); + } - })(); - }); - buf_arg_value.free(); - return diplomat_out; - } + } - canonical_iana_from_bcp47(arg_value) { - const buf_arg_value = diplomatRuntime.DiplomatBuf.str8(wasm, arg_value); - const diplomat_out = diplomatRuntime.withDiplomatWrite(wasm, (write) => { - return (() => { + canonicalIanaFromBcp47(value) { + + const valueSlice = diplomatRuntime.DiplomatBuf.str8(wasm, value); + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XTimeZoneIdMapperWithFastCanonicalization_canonical_iana_from_bcp47(diplomat_receive_buffer, this.underlying, buf_arg_value.ptr, buf_arg_value.size, write); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = {}; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = TimeZoneInvalidIdError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); + + const write = wasm.diplomat_buffer_write_create(0); + const result = wasm.ICU4XTimeZoneIdMapperWithFastCanonicalization_canonical_iana_from_bcp47(diplomat_receive_buffer, this.ffiValue, valueSlice.ptr, valueSlice.size, write); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = TimeZoneInvalidIdError[Array.from(TimeZoneInvalidIdError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('TimeZoneInvalidIdError: ' + cause.value, { cause }); + } + return diplomatRuntime.readString8(wasm, wasm.diplomat_buffer_write_get_bytes(write), wasm.diplomat_buffer_write_len(write)); + } finally { + + valueSlice.free(); + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + wasm.diplomat_buffer_write_destroy(write); + } - })(); - }); - buf_arg_value.free(); - return diplomat_out; - } -} + } + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/TimeZoneInvalidIdError.d.ts b/ffi/capi/bindings/js/TimeZoneInvalidIdError.d.ts index 03a498a821d..c340e279497 100644 --- a/ffi/capi/bindings/js/TimeZoneInvalidIdError.d.ts +++ b/ffi/capi/bindings/js/TimeZoneInvalidIdError.d.ts @@ -1,8 +1,17 @@ +// generated by diplomat-tool +import type { pointer, char } from "./diplomat-runtime.d.ts"; + +// Base enumerator definition +export class TimeZoneInvalidIdError { + constructor(value : TimeZoneInvalidIdError | string); + + get value() : string; + + get ffiValue() : number; + + static TodoZst : TimeZoneInvalidIdError; + + + -/** - */ -export enum TimeZoneInvalidIdError { - /** - */ - TodoZst = 'TodoZst', } \ No newline at end of file diff --git a/ffi/capi/bindings/js/TimeZoneInvalidIdError.mjs b/ffi/capi/bindings/js/TimeZoneInvalidIdError.mjs index 1656d4f0c49..6bafde79066 100644 --- a/ffi/capi/bindings/js/TimeZoneInvalidIdError.mjs +++ b/ffi/capi/bindings/js/TimeZoneInvalidIdError.mjs @@ -1,14 +1,39 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" +// generated by diplomat-tool +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -export const TimeZoneInvalidIdError_js_to_rust = { - "TodoZst": 0, -}; +// Base enumerator definition +export class TimeZoneInvalidIdError { + #value = undefined; -export const TimeZoneInvalidIdError_rust_to_js = { - [0]: "TodoZst", -}; + static values = new Map([ + ["TodoZst", 0] + ]); + constructor(value) { + if (value instanceof TimeZoneInvalidIdError) { + this.#value = value.value; + return; + } -export const TimeZoneInvalidIdError = { - "TodoZst": "TodoZst", -}; + if (TimeZoneInvalidIdError.values.has(value)) { + this.#value = value; + return; + } + + throw TypeError(value + " is not a TimeZoneInvalidIdError and does not correspond to any of its enumerator values."); + } + + get value() { + return this.#value; + } + + get ffiValue() { + return TimeZoneInvalidIdError.values.get(this.#value); + } + + static TodoZst = new TimeZoneInvalidIdError("TodoZst"); + + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/TimeZoneInvalidOffsetError.d.ts b/ffi/capi/bindings/js/TimeZoneInvalidOffsetError.d.ts index 553e2aa1fb5..dd98cc5d468 100644 --- a/ffi/capi/bindings/js/TimeZoneInvalidOffsetError.d.ts +++ b/ffi/capi/bindings/js/TimeZoneInvalidOffsetError.d.ts @@ -1,10 +1,19 @@ +// generated by diplomat-tool +import type { pointer, char } from "./diplomat-runtime.d.ts"; -/** +// Base enumerator definition +/** Additional information: [1](https://docs.rs/icu/latest/icu/timezone/struct.InvalidOffsetError.html) +*/ +export class TimeZoneInvalidOffsetError { + constructor(value : TimeZoneInvalidOffsetError | string); + + get value() : string; + + get ffiValue() : number; + + static TodoZst : TimeZoneInvalidOffsetError; + + + - * Additional information: {@link https://docs.rs/icu/latest/icu/timezone/struct.InvalidOffsetError.html 1} - */ -export enum TimeZoneInvalidOffsetError { - /** - */ - TodoZst = 'TodoZst', } \ No newline at end of file diff --git a/ffi/capi/bindings/js/TimeZoneInvalidOffsetError.mjs b/ffi/capi/bindings/js/TimeZoneInvalidOffsetError.mjs index 538453a0a2f..253052271a1 100644 --- a/ffi/capi/bindings/js/TimeZoneInvalidOffsetError.mjs +++ b/ffi/capi/bindings/js/TimeZoneInvalidOffsetError.mjs @@ -1,14 +1,41 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" +// generated by diplomat-tool +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -export const TimeZoneInvalidOffsetError_js_to_rust = { - "TodoZst": 0, -}; +// Base enumerator definition +/** Additional information: [1](https://docs.rs/icu/latest/icu/timezone/struct.InvalidOffsetError.html) +*/ +export class TimeZoneInvalidOffsetError { + #value = undefined; -export const TimeZoneInvalidOffsetError_rust_to_js = { - [0]: "TodoZst", -}; + static values = new Map([ + ["TodoZst", 0] + ]); + constructor(value) { + if (value instanceof TimeZoneInvalidOffsetError) { + this.#value = value.value; + return; + } -export const TimeZoneInvalidOffsetError = { - "TodoZst": "TodoZst", -}; + if (TimeZoneInvalidOffsetError.values.has(value)) { + this.#value = value; + return; + } + + throw TypeError(value + " is not a TimeZoneInvalidOffsetError and does not correspond to any of its enumerator values."); + } + + get value() { + return this.#value; + } + + get ffiValue() { + return TimeZoneInvalidOffsetError.values.get(this.#value); + } + + static TodoZst = new TimeZoneInvalidOffsetError("TodoZst"); + + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/TitlecaseMapper.d.ts b/ffi/capi/bindings/js/TitlecaseMapper.d.ts index 22325cf4c9b..2171b75cf08 100644 --- a/ffi/capi/bindings/js/TitlecaseMapper.d.ts +++ b/ffi/capi/bindings/js/TitlecaseMapper.d.ts @@ -1,31 +1,22 @@ -import { FFIError } from "./diplomat-runtime" -import { DataError } from "./DataError"; -import { DataProvider } from "./DataProvider"; -import { Locale } from "./Locale"; -import { TitlecaseOptionsV1 } from "./TitlecaseOptionsV1"; +// generated by diplomat-tool +import type { DataProvider } from "./DataProvider" +import type { Locale } from "./Locale" +import type { TitlecaseOptions } from "./TitlecaseOptions" +import type { pointer, char } from "./diplomat-runtime.d.ts"; -/** - * See the {@link https://docs.rs/icu/latest/icu/casemap/struct.TitlecaseMapper.html Rust documentation for `TitlecaseMapper`} for more information. - */ +/** See the [Rust documentation for `TitlecaseMapper`](https://docs.rs/icu/latest/icu/casemap/struct.TitlecaseMapper.html) for more information. +*/ export class TitlecaseMapper { + - /** + get ffiValue(): pointer; - * Construct a new `TitlecaseMapper` instance - * See the {@link https://docs.rs/icu/latest/icu/casemap/struct.TitlecaseMapper.html#method.new Rust documentation for `new`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static create(provider: DataProvider): TitlecaseMapper | never; + static create(provider: DataProvider): TitlecaseMapper; - /** + titlecaseSegment(s: string, locale: Locale, options: TitlecaseOptions): string; - * Returns the full titlecase mapping of the given string + - * The `v1` refers to the version of the options struct, which may change as we add more options - - * See the {@link https://docs.rs/icu/latest/icu/casemap/struct.TitlecaseMapper.html#method.titlecase_segment Rust documentation for `titlecase_segment`} for more information. - */ - titlecase_segment_v1(s: string, locale: Locale, options: TitlecaseOptionsV1): string; -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/TitlecaseMapper.mjs b/ffi/capi/bindings/js/TitlecaseMapper.mjs index fdd18c43dda..fa7f7b113fd 100644 --- a/ffi/capi/bindings/js/TitlecaseMapper.mjs +++ b/ffi/capi/bindings/js/TitlecaseMapper.mjs @@ -1,48 +1,84 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" -import { DataError_js_to_rust, DataError_rust_to_js } from "./DataError.mjs" -import { LeadingAdjustment_js_to_rust, LeadingAdjustment_rust_to_js } from "./LeadingAdjustment.mjs" -import { TrailingCase_js_to_rust, TrailingCase_rust_to_js } from "./TrailingCase.mjs" - -const TitlecaseMapper_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XTitlecaseMapper_destroy(underlying); -}); +// generated by diplomat-tool +import { DataError } from "./DataError.mjs" +import { DataProvider } from "./DataProvider.mjs" +import { Locale } from "./Locale.mjs" +import { TitlecaseOptions } from "./TitlecaseOptions.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; + +/** See the [Rust documentation for `TitlecaseMapper`](https://docs.rs/icu/latest/icu/casemap/struct.TitlecaseMapper.html) for more information. +*/ + +const TitlecaseMapper_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XTitlecaseMapper_destroy(ptr); +}); export class TitlecaseMapper { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - TitlecaseMapper_box_destroy_registry.register(this, underlying); + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + + constructor(ptr, selfEdge) { + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + TitlecaseMapper_box_destroy_registry.register(this, this.#ptr); + } + + get ffiValue() { + return this.#ptr; } - } - - static create(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XTitlecaseMapper_create(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new TitlecaseMapper(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - titlecase_segment_v1(arg_s, arg_locale, arg_options) { - const buf_arg_s = diplomatRuntime.DiplomatBuf.str8(wasm, arg_s); - const field_leading_adjustment_arg_options = arg_options["leading_adjustment"]; - const field_trailing_case_arg_options = arg_options["trailing_case"]; - const diplomat_out = diplomatRuntime.withDiplomatWrite(wasm, (write) => { - return wasm.ICU4XTitlecaseMapper_titlecase_segment_v1(this.underlying, buf_arg_s.ptr, buf_arg_s.size, arg_locale.underlying, LeadingAdjustment_js_to_rust[field_leading_adjustment_arg_options], TrailingCase_js_to_rust[field_trailing_case_arg_options], write); - }); - buf_arg_s.free(); - return diplomat_out; - } -} + + + static create(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XTitlecaseMapper_create(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new TitlecaseMapper(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + titlecaseSegment(s, locale, options) { + + const sSlice = diplomatRuntime.DiplomatBuf.str8(wasm, s); + + let slice_cleanup_callbacks = []; + + const write = wasm.diplomat_buffer_write_create(0); + wasm.ICU4XTitlecaseMapper_titlecase_segment_v1(this.ffiValue, sSlice.ptr, sSlice.size, locale.ffiValue, ...options._intoFFI(slice_cleanup_callbacks, {}), write); + + try { + + return diplomatRuntime.readString8(wasm, wasm.diplomat_buffer_write_get_bytes(write), wasm.diplomat_buffer_write_len(write)); + } finally { + + for (let cleanup of slice_cleanup_callbacks) { + cleanup(); + } + + sSlice.free(); + + wasm.diplomat_buffer_write_destroy(write); + + } + } + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/TitlecaseOptions.d.ts b/ffi/capi/bindings/js/TitlecaseOptions.d.ts new file mode 100644 index 00000000000..b873cff9612 --- /dev/null +++ b/ffi/capi/bindings/js/TitlecaseOptions.d.ts @@ -0,0 +1,19 @@ +// generated by diplomat-tool +import type { LeadingAdjustment } from "./LeadingAdjustment" +import type { TrailingCase } from "./TrailingCase" +import type { pointer, char } from "./diplomat-runtime.d.ts"; + + +/** See the [Rust documentation for `TitlecaseOptions`](https://docs.rs/icu/latest/icu/casemap/titlecase/struct.TitlecaseOptions.html) for more information. +*/ +export class TitlecaseOptions { + get leadingAdjustment() : LeadingAdjustment; + set leadingAdjustment(value: LeadingAdjustment); + get trailingCase() : TrailingCase; + set trailingCase(value: TrailingCase); + + static defaultOptions(): TitlecaseOptions; + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/TitlecaseOptions.mjs b/ffi/capi/bindings/js/TitlecaseOptions.mjs new file mode 100644 index 00000000000..94da5bb89be --- /dev/null +++ b/ffi/capi/bindings/js/TitlecaseOptions.mjs @@ -0,0 +1,66 @@ +// generated by diplomat-tool +import { LeadingAdjustment } from "./LeadingAdjustment.mjs" +import { TrailingCase } from "./TrailingCase.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; + + +/** See the [Rust documentation for `TitlecaseOptions`](https://docs.rs/icu/latest/icu/casemap/titlecase/struct.TitlecaseOptions.html) for more information. +*/ +export class TitlecaseOptions { + #leadingAdjustment; + get leadingAdjustment() { + return this.#leadingAdjustment; + } + set leadingAdjustment(value) { + this.#leadingAdjustment = value; + } + #trailingCase; + get trailingCase() { + return this.#trailingCase; + } + set trailingCase(value) { + this.#trailingCase = value; + } + + // Return this struct in FFI function friendly format. + // Returns an array that can be expanded with spread syntax (...) + + _intoFFI( + slice_cleanup_callbacks, + appendArrayMap + ) { + return [this.#leadingAdjustment.ffiValue, this.#trailingCase.ffiValue] + } + + // 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. + _fromFFI(ptr) { + const leadingAdjustmentDeref = diplomatRuntime.enumDiscriminant(wasm, ptr); + this.#leadingAdjustment = LeadingAdjustment[Array.from(LeadingAdjustment.values.keys())[leadingAdjustmentDeref]]; + const trailingCaseDeref = diplomatRuntime.enumDiscriminant(wasm, ptr + 4); + this.#trailingCase = TrailingCase[Array.from(TrailingCase.values.keys())[trailingCaseDeref]]; + + return this; + } + static defaultOptions() { + + const diplomat_receive_buffer = wasm.diplomat_alloc(8, 4); + const result = wasm.ICU4XTitlecaseOptionsV1_default_options(diplomat_receive_buffer); + + try { + + return new TitlecaseOptions()._fromFFI(diplomat_receive_buffer); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 8, 4); + + } + } + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/TitlecaseOptionsV1.d.ts b/ffi/capi/bindings/js/TitlecaseOptionsV1.d.ts deleted file mode 100644 index 416feefee3e..00000000000 --- a/ffi/capi/bindings/js/TitlecaseOptionsV1.d.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { LeadingAdjustment } from "./LeadingAdjustment"; -import { TrailingCase } from "./TrailingCase"; - -/** - - * See the {@link https://docs.rs/icu/latest/icu/casemap/titlecase/struct.TitlecaseOptions.html Rust documentation for `TitlecaseOptions`} for more information. - */ -export class TitlecaseOptionsV1 { - leading_adjustment: LeadingAdjustment; - trailing_case: TrailingCase; - - /** - - * See the {@link https://docs.rs/icu/latest/icu/casemap/titlecase/struct.TitlecaseOptions.html#method.default Rust documentation for `default`} for more information. - */ - static default_options(): TitlecaseOptionsV1; -} diff --git a/ffi/capi/bindings/js/TitlecaseOptionsV1.mjs b/ffi/capi/bindings/js/TitlecaseOptionsV1.mjs deleted file mode 100644 index 5ace5cd1628..00000000000 --- a/ffi/capi/bindings/js/TitlecaseOptionsV1.mjs +++ /dev/null @@ -1,21 +0,0 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" -import { LeadingAdjustment_js_to_rust, LeadingAdjustment_rust_to_js } from "./LeadingAdjustment.mjs" -import { TrailingCase_js_to_rust, TrailingCase_rust_to_js } from "./TrailingCase.mjs" - -export class TitlecaseOptionsV1 { - constructor(underlying) { - this.leading_adjustment = LeadingAdjustment_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, underlying)]; - this.trailing_case = TrailingCase_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, underlying + 4)]; - } - - static default_options() { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(8, 4); - wasm.ICU4XTitlecaseOptionsV1_default_options(diplomat_receive_buffer); - const out = new TitlecaseOptionsV1(diplomat_receive_buffer); - wasm.diplomat_free(diplomat_receive_buffer, 8, 4); - return out; - })(); - } -} diff --git a/ffi/capi/bindings/js/TrailingCase.d.ts b/ffi/capi/bindings/js/TrailingCase.d.ts index 64eb66b1782..48f3dd9dfc9 100644 --- a/ffi/capi/bindings/js/TrailingCase.d.ts +++ b/ffi/capi/bindings/js/TrailingCase.d.ts @@ -1,13 +1,21 @@ +// generated by diplomat-tool +import type { pointer, char } from "./diplomat-runtime.d.ts"; + +// Base enumerator definition +/** See the [Rust documentation for `TrailingCase`](https://docs.rs/icu/latest/icu/casemap/titlecase/enum.TrailingCase.html) for more information. +*/ +export class TrailingCase { + constructor(value : TrailingCase | string); + + get value() : string; + + get ffiValue() : number; + + static Lower : TrailingCase; + + static Unchanged : TrailingCase; + + + -/** - - * See the {@link https://docs.rs/icu/latest/icu/casemap/titlecase/enum.TrailingCase.html Rust documentation for `TrailingCase`} for more information. - */ -export enum TrailingCase { - /** - */ - Lower = 'Lower', - /** - */ - Unchanged = 'Unchanged', } \ No newline at end of file diff --git a/ffi/capi/bindings/js/TrailingCase.mjs b/ffi/capi/bindings/js/TrailingCase.mjs index 8ff7e6d1674..46cb99afffe 100644 --- a/ffi/capi/bindings/js/TrailingCase.mjs +++ b/ffi/capi/bindings/js/TrailingCase.mjs @@ -1,17 +1,44 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" - -export const TrailingCase_js_to_rust = { - "Lower": 0, - "Unchanged": 1, -}; - -export const TrailingCase_rust_to_js = { - [0]: "Lower", - [1]: "Unchanged", -}; - -export const TrailingCase = { - "Lower": "Lower", - "Unchanged": "Unchanged", -}; +// generated by diplomat-tool +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; + +// Base enumerator definition +/** See the [Rust documentation for `TrailingCase`](https://docs.rs/icu/latest/icu/casemap/titlecase/enum.TrailingCase.html) for more information. +*/ +export class TrailingCase { + #value = undefined; + + static values = new Map([ + ["Lower", 0], + ["Unchanged", 1] + ]); + constructor(value) { + if (value instanceof TrailingCase) { + this.#value = value.value; + return; + } + + if (TrailingCase.values.has(value)) { + this.#value = value; + return; + } + + throw TypeError(value + " is not a TrailingCase and does not correspond to any of its enumerator values."); + } + + get value() { + return this.#value; + } + + get ffiValue() { + return TrailingCase.values.get(this.#value); + } + + static Lower = new TrailingCase("Lower"); + + static Unchanged = new TrailingCase("Unchanged"); + + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/TransformResult.d.ts b/ffi/capi/bindings/js/TransformResult.d.ts index 91e699a10eb..8d5a77a57d0 100644 --- a/ffi/capi/bindings/js/TransformResult.d.ts +++ b/ffi/capi/bindings/js/TransformResult.d.ts @@ -1,13 +1,21 @@ +// generated by diplomat-tool +import type { pointer, char } from "./diplomat-runtime.d.ts"; + +// Base enumerator definition +/** See the [Rust documentation for `TransformResult`](https://docs.rs/icu/latest/icu/locale/enum.TransformResult.html) for more information. +*/ +export class TransformResult { + constructor(value : TransformResult | string); + + get value() : string; + + get ffiValue() : number; + + static Modified : TransformResult; + + static Unmodified : TransformResult; + + + -/** - - * See the {@link https://docs.rs/icu/latest/icu/locale/enum.TransformResult.html Rust documentation for `TransformResult`} for more information. - */ -export enum TransformResult { - /** - */ - Modified = 'Modified', - /** - */ - Unmodified = 'Unmodified', } \ No newline at end of file diff --git a/ffi/capi/bindings/js/TransformResult.mjs b/ffi/capi/bindings/js/TransformResult.mjs index ef8e607652b..9100f595155 100644 --- a/ffi/capi/bindings/js/TransformResult.mjs +++ b/ffi/capi/bindings/js/TransformResult.mjs @@ -1,17 +1,44 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" - -export const TransformResult_js_to_rust = { - "Modified": 0, - "Unmodified": 1, -}; - -export const TransformResult_rust_to_js = { - [0]: "Modified", - [1]: "Unmodified", -}; - -export const TransformResult = { - "Modified": "Modified", - "Unmodified": "Unmodified", -}; +// generated by diplomat-tool +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; + +// Base enumerator definition +/** See the [Rust documentation for `TransformResult`](https://docs.rs/icu/latest/icu/locale/enum.TransformResult.html) for more information. +*/ +export class TransformResult { + #value = undefined; + + static values = new Map([ + ["Modified", 0], + ["Unmodified", 1] + ]); + constructor(value) { + if (value instanceof TransformResult) { + this.#value = value.value; + return; + } + + if (TransformResult.values.has(value)) { + this.#value = value; + return; + } + + throw TypeError(value + " is not a TransformResult and does not correspond to any of its enumerator values."); + } + + get value() { + return this.#value; + } + + get ffiValue() { + return TransformResult.values.get(this.#value); + } + + static Modified = new TransformResult("Modified"); + + static Unmodified = new TransformResult("Unmodified"); + + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/UnicodeSetData.d.ts b/ffi/capi/bindings/js/UnicodeSetData.d.ts index 4a5212daf2c..664a4f3dea1 100644 --- a/ffi/capi/bindings/js/UnicodeSetData.d.ts +++ b/ffi/capi/bindings/js/UnicodeSetData.d.ts @@ -1,82 +1,39 @@ -import { u32, char } from "./diplomat-runtime" -import { FFIError } from "./diplomat-runtime" -import { DataError } from "./DataError"; -import { DataProvider } from "./DataProvider"; -import { Locale } from "./Locale"; - -/** - - * An ICU4X Unicode Set Property object, capable of querying whether a code point is contained in a set based on a Unicode property. - - * See the {@link https://docs.rs/icu/latest/icu/properties/index.html Rust documentation for `properties`} for more information. - - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/struct.UnicodeSetData.html Rust documentation for `UnicodeSetData`} for more information. - - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/struct.UnicodeSetDataBorrowed.html Rust documentation for `UnicodeSetDataBorrowed`} for more information. - */ +// generated by diplomat-tool +import type { DataProvider } from "./DataProvider" +import type { Locale } from "./Locale" +import type { pointer, char } from "./diplomat-runtime.d.ts"; + + +/** An ICU4X Unicode Set Property object, capable of querying whether a code point is contained in a set based on a Unicode property. +* +*See the [Rust documentation for `properties`](https://docs.rs/icu/latest/icu/properties/index.html) for more information. +* +*See the [Rust documentation for `UnicodeSetData`](https://docs.rs/icu/latest/icu/properties/sets/struct.UnicodeSetData.html) for more information. +* +*See the [Rust documentation for `UnicodeSetDataBorrowed`](https://docs.rs/icu/latest/icu/properties/sets/struct.UnicodeSetDataBorrowed.html) for more information. +*/ export class UnicodeSetData { + - /** - - * Checks whether the string is in the set. - - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/struct.UnicodeSetDataBorrowed.html#method.contains Rust documentation for `contains`} for more information. - */ - contains(s: string): boolean; - - /** - - * Checks whether the code point is in the set. - - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/struct.UnicodeSetDataBorrowed.html#method.contains_char Rust documentation for `contains_char`} for more information. - */ - contains_char(cp: char): boolean; - - /** - - * Checks whether the code point (specified as a 32 bit integer, in UTF-32) is in the set. - */ - contains32(cp: u32): boolean; - - /** + get ffiValue(): pointer; - * See the {@link https://docs.rs/icu/latest/icu/properties/sets/fn.basic_emoji.html Rust documentation for `basic_emoji`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_basic_emoji(provider: DataProvider): UnicodeSetData | never; - /** + contains(s: string): boolean; - * See the {@link https://docs.rs/icu/latest/icu/properties/exemplar_chars/fn.exemplars_main.html Rust documentation for `exemplars_main`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_exemplars_main(provider: DataProvider, locale: Locale): UnicodeSetData | never; + containsChar(cp: char): boolean; - /** + static loadBasicEmoji(provider: DataProvider): UnicodeSetData; - * See the {@link https://docs.rs/icu/latest/icu/properties/exemplar_chars/fn.exemplars_auxiliary.html Rust documentation for `exemplars_auxiliary`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_exemplars_auxiliary(provider: DataProvider, locale: Locale): UnicodeSetData | never; + static loadExemplarsMain(provider: DataProvider, locale: Locale): UnicodeSetData; - /** + static loadExemplarsAuxiliary(provider: DataProvider, locale: Locale): UnicodeSetData; - * See the {@link https://docs.rs/icu/latest/icu/properties/exemplar_chars/fn.exemplars_punctuation.html Rust documentation for `exemplars_punctuation`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_exemplars_punctuation(provider: DataProvider, locale: Locale): UnicodeSetData | never; + static loadExemplarsPunctuation(provider: DataProvider, locale: Locale): UnicodeSetData; - /** + static loadExemplarsNumbers(provider: DataProvider, locale: Locale): UnicodeSetData; - * See the {@link https://docs.rs/icu/latest/icu/properties/exemplar_chars/fn.exemplars_numbers.html Rust documentation for `exemplars_numbers`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_exemplars_numbers(provider: DataProvider, locale: Locale): UnicodeSetData | never; + static loadExemplarsIndex(provider: DataProvider, locale: Locale): UnicodeSetData; - /** + - * See the {@link https://docs.rs/icu/latest/icu/properties/exemplar_chars/fn.exemplars_index.html Rust documentation for `exemplars_index`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static load_exemplars_index(provider: DataProvider, locale: Locale): UnicodeSetData | never; -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/UnicodeSetData.mjs b/ffi/capi/bindings/js/UnicodeSetData.mjs index 1c158aef022..eea5083626e 100644 --- a/ffi/capi/bindings/js/UnicodeSetData.mjs +++ b/ffi/capi/bindings/js/UnicodeSetData.mjs @@ -1,135 +1,185 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" -import { DataError_js_to_rust, DataError_rust_to_js } from "./DataError.mjs" +// generated by diplomat-tool +import { DataError } from "./DataError.mjs" +import { DataProvider } from "./DataProvider.mjs" +import { Locale } from "./Locale.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -const UnicodeSetData_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XUnicodeSetData_destroy(underlying); -}); +/** An ICU4X Unicode Set Property object, capable of querying whether a code point is contained in a set based on a Unicode property. +* +*See the [Rust documentation for `properties`](https://docs.rs/icu/latest/icu/properties/index.html) for more information. +* +*See the [Rust documentation for `UnicodeSetData`](https://docs.rs/icu/latest/icu/properties/sets/struct.UnicodeSetData.html) for more information. +* +*See the [Rust documentation for `UnicodeSetDataBorrowed`](https://docs.rs/icu/latest/icu/properties/sets/struct.UnicodeSetDataBorrowed.html) for more information. +*/ + +const UnicodeSetData_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XUnicodeSetData_destroy(ptr); +}); export class UnicodeSetData { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - UnicodeSetData_box_destroy_registry.register(this, underlying); + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + + constructor(ptr, selfEdge) { + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + UnicodeSetData_box_destroy_registry.register(this, this.#ptr); + } + + get ffiValue() { + return this.#ptr; + } + + + contains(s) { + + const sSlice = diplomatRuntime.DiplomatBuf.str8(wasm, s); + const result = wasm.ICU4XUnicodeSetData_contains(this.ffiValue, sSlice.ptr, sSlice.size); + + try { + + return result; + } finally { + + sSlice.free(); + + } + } + + containsChar(cp) { + const result = wasm.ICU4XUnicodeSetData_contains_char(this.ffiValue, diplomatRuntime.extractCodePoint(cp, 'cp')); + + try { + + return result; + } finally { + + } + } + + static loadBasicEmoji(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XUnicodeSetData_load_basic_emoji(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new UnicodeSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } } - } - - contains(arg_s) { - const buf_arg_s = diplomatRuntime.DiplomatBuf.str8(wasm, arg_s); - const diplomat_out = wasm.ICU4XUnicodeSetData_contains(this.underlying, buf_arg_s.ptr, buf_arg_s.size); - buf_arg_s.free(); - return diplomat_out; - } - - contains_char(arg_cp) { - return wasm.ICU4XUnicodeSetData_contains_char(this.underlying, diplomatRuntime.extractCodePoint(arg_cp, 'arg_cp')); - } - - contains32(arg_cp) { - return wasm.ICU4XUnicodeSetData_contains32(this.underlying, arg_cp); - } - - static load_basic_emoji(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XUnicodeSetData_load_basic_emoji(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new UnicodeSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_exemplars_main(arg_provider, arg_locale) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XUnicodeSetData_load_exemplars_main(diplomat_receive_buffer, arg_provider.underlying, arg_locale.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new UnicodeSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_exemplars_auxiliary(arg_provider, arg_locale) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XUnicodeSetData_load_exemplars_auxiliary(diplomat_receive_buffer, arg_provider.underlying, arg_locale.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new UnicodeSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_exemplars_punctuation(arg_provider, arg_locale) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XUnicodeSetData_load_exemplars_punctuation(diplomat_receive_buffer, arg_provider.underlying, arg_locale.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new UnicodeSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_exemplars_numbers(arg_provider, arg_locale) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XUnicodeSetData_load_exemplars_numbers(diplomat_receive_buffer, arg_provider.underlying, arg_locale.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new UnicodeSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static load_exemplars_index(arg_provider, arg_locale) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XUnicodeSetData_load_exemplars_index(diplomat_receive_buffer, arg_provider.underlying, arg_locale.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new UnicodeSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } -} + + static loadExemplarsMain(provider, locale) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XUnicodeSetData_load_exemplars_main(diplomat_receive_buffer, provider.ffiValue, locale.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new UnicodeSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadExemplarsAuxiliary(provider, locale) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XUnicodeSetData_load_exemplars_auxiliary(diplomat_receive_buffer, provider.ffiValue, locale.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new UnicodeSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadExemplarsPunctuation(provider, locale) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XUnicodeSetData_load_exemplars_punctuation(diplomat_receive_buffer, provider.ffiValue, locale.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new UnicodeSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadExemplarsNumbers(provider, locale) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XUnicodeSetData_load_exemplars_numbers(diplomat_receive_buffer, provider.ffiValue, locale.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new UnicodeSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static loadExemplarsIndex(provider, locale) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XUnicodeSetData_load_exemplars_index(diplomat_receive_buffer, provider.ffiValue, locale.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new UnicodeSetData(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/UnitsConverter.d.ts b/ffi/capi/bindings/js/UnitsConverter.d.ts index 39b02bd87d5..a668ea6e27c 100644 --- a/ffi/capi/bindings/js/UnitsConverter.d.ts +++ b/ffi/capi/bindings/js/UnitsConverter.d.ts @@ -1,28 +1,23 @@ -import { f64 } from "./diplomat-runtime" +// generated by diplomat-tool +import type { pointer, char } from "./diplomat-runtime.d.ts"; -/** - * An ICU4X Units Converter object, capable of converting between two {@link MeasureUnit `MeasureUnit`}s. - - * You can create an instance of this object using {@link UnitsConverterFactory `UnitsConverterFactory`} by calling the `converter` method. - - * See the {@link https://docs.rs/icu/latest/icu/experimental/units/converter/struct.UnitsConverter.html Rust documentation for `UnitsConverter`} for more information. - */ +/** An ICU4X Units Converter object, capable of converting between two [`MeasureUnit`]s. +* +*You can create an instance of this object using [`UnitsConverterFactory`] by calling the `converter` method. +* +*See the [Rust documentation for `UnitsConverter`](https://docs.rs/icu/latest/icu/experimental/units/converter/struct.UnitsConverter.html) for more information. +*/ export class UnitsConverter { + - /** + get ffiValue(): pointer; - * Converts the input value in float from the input unit to the output unit (that have been used to create this converter). NOTE: The conversion using floating-point operations is not as accurate as the conversion using ratios. - * See the {@link https://docs.rs/icu/latest/icu/experimental/units/converter/struct.UnitsConverter.html#method.convert Rust documentation for `convert`} for more information. - */ - convert_f64(value: f64): f64; + convert(value: number): number; - /** + clone(): UnitsConverter; - * Clones the current {@link UnitsConverter `UnitsConverter`} object. + - * See the {@link https://docs.rs/icu/latest/icu/experimental/units/converter/struct.UnitsConverter.html#method.clone Rust documentation for `clone`} for more information. - */ - clone(): UnitsConverter; -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/UnitsConverter.mjs b/ffi/capi/bindings/js/UnitsConverter.mjs index 83b5394273d..2e65735f4bb 100644 --- a/ffi/capi/bindings/js/UnitsConverter.mjs +++ b/ffi/capi/bindings/js/UnitsConverter.mjs @@ -1,25 +1,62 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" +// generated by diplomat-tool +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -const UnitsConverter_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XUnitsConverter_destroy(underlying); -}); +/** An ICU4X Units Converter object, capable of converting between two [`MeasureUnit`]s. +* +*You can create an instance of this object using [`UnitsConverterFactory`] by calling the `converter` method. +* +*See the [Rust documentation for `UnitsConverter`](https://docs.rs/icu/latest/icu/experimental/units/converter/struct.UnitsConverter.html) for more information. +*/ + +const UnitsConverter_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XUnitsConverter_destroy(ptr); +}); export class UnitsConverter { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - UnitsConverter_box_destroy_registry.register(this, underlying); + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + + constructor(ptr, selfEdge) { + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + UnitsConverter_box_destroy_registry.register(this, this.#ptr); + } + + get ffiValue() { + return this.#ptr; + } + + + convert(value) { + const result = wasm.ICU4XUnitsConverter_convert_f64(this.ffiValue, value); + + try { + + return result; + } finally { + + } + } + + clone() { + const result = wasm.ICU4XUnitsConverter_clone(this.ffiValue); + + try { + + return new UnitsConverter(result, []); + } finally { + + } } - } - convert_f64(arg_value) { - return wasm.ICU4XUnitsConverter_convert_f64(this.underlying, arg_value); - } + - clone() { - return new UnitsConverter(wasm.ICU4XUnitsConverter_clone(this.underlying), true, []); - } -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/UnitsConverterFactory.d.ts b/ffi/capi/bindings/js/UnitsConverterFactory.d.ts index 561b252711e..0329f571642 100644 --- a/ffi/capi/bindings/js/UnitsConverterFactory.d.ts +++ b/ffi/capi/bindings/js/UnitsConverterFactory.d.ts @@ -1,40 +1,29 @@ -import { FFIError } from "./diplomat-runtime" -import { DataError } from "./DataError"; -import { DataProvider } from "./DataProvider"; -import { MeasureUnit } from "./MeasureUnit"; -import { MeasureUnitParser } from "./MeasureUnitParser"; -import { UnitsConverter } from "./UnitsConverter"; - -/** - - * An ICU4X Units Converter Factory object, capable of creating converters a {@link UnitsConverter `UnitsConverter`} for converting between two {@link MeasureUnit `MeasureUnit`}s. Also, it can parse the CLDR unit identifier (e.g. `meter-per-square-second`) and get the {@link MeasureUnit `MeasureUnit`}. - - * See the {@link https://docs.rs/icu/latest/icu/experimental/units/converter_factory/struct.ConverterFactory.html Rust documentation for `ConverterFactory`} for more information. - */ +// generated by diplomat-tool +import type { DataProvider } from "./DataProvider" +import type { MeasureUnit } from "./MeasureUnit" +import type { MeasureUnitParser } from "./MeasureUnitParser" +import type { UnitsConverter } from "./UnitsConverter" +import type { pointer, char } from "./diplomat-runtime.d.ts"; + + +/** An ICU4X Units Converter Factory object, capable of creating converters a [`UnitsConverter`] +*for converting between two [`MeasureUnit`]s. +*Also, it can parse the CLDR unit identifier (e.g. `meter-per-square-second`) and get the [`MeasureUnit`]. +* +*See the [Rust documentation for `ConverterFactory`](https://docs.rs/icu/latest/icu/experimental/units/converter_factory/struct.ConverterFactory.html) for more information. +*/ export class UnitsConverterFactory { + - /** - - * Construct a new {@link UnitsConverterFactory `UnitsConverterFactory`} instance. - - * See the {@link https://docs.rs/icu/latest/icu/experimental/units/converter_factory/struct.ConverterFactory.html#method.new Rust documentation for `new`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static create(provider: DataProvider): UnitsConverterFactory | never; + get ffiValue(): pointer; - /** - * Creates a new {@link UnitsConverter `UnitsConverter`} from the input and output {@link MeasureUnit `MeasureUnit`}s. Returns nothing if the conversion between the two units is not possible. For example, conversion between `meter` and `second` is not possible. + static create(provider: DataProvider): UnitsConverterFactory; - * See the {@link https://docs.rs/icu/latest/icu/experimental/units/converter_factory/struct.ConverterFactory.html#method.converter Rust documentation for `converter`} for more information. - */ - converter(from: MeasureUnit, to: MeasureUnit): UnitsConverter | undefined; + converter(from: MeasureUnit, to: MeasureUnit): UnitsConverter | null; - /** + parser(): MeasureUnitParser; - * Creates a parser to parse the CLDR unit identifier (e.g. `meter-per-square-second`) and get the {@link MeasureUnit `MeasureUnit`}. + - * See the {@link https://docs.rs/icu/latest/icu/experimental/units/converter_factory/struct.ConverterFactory.html#method.parser Rust documentation for `parser`} for more information. - */ - parser(): MeasureUnitParser; -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/UnitsConverterFactory.mjs b/ffi/capi/bindings/js/UnitsConverterFactory.mjs index e1232c3aefa..e3d1f50597a 100644 --- a/ffi/capi/bindings/js/UnitsConverterFactory.mjs +++ b/ffi/capi/bindings/js/UnitsConverterFactory.mjs @@ -1,48 +1,89 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" -import { DataError_js_to_rust, DataError_rust_to_js } from "./DataError.mjs" +// generated by diplomat-tool +import { DataError } from "./DataError.mjs" +import { DataProvider } from "./DataProvider.mjs" +import { MeasureUnit } from "./MeasureUnit.mjs" import { MeasureUnitParser } from "./MeasureUnitParser.mjs" import { UnitsConverter } from "./UnitsConverter.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -const UnitsConverterFactory_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XUnitsConverterFactory_destroy(underlying); -}); +/** An ICU4X Units Converter Factory object, capable of creating converters a [`UnitsConverter`] +*for converting between two [`MeasureUnit`]s. +*Also, it can parse the CLDR unit identifier (e.g. `meter-per-square-second`) and get the [`MeasureUnit`]. +* +*See the [Rust documentation for `ConverterFactory`](https://docs.rs/icu/latest/icu/experimental/units/converter_factory/struct.ConverterFactory.html) for more information. +*/ + +const UnitsConverterFactory_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XUnitsConverterFactory_destroy(ptr); +}); export class UnitsConverterFactory { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - UnitsConverterFactory_box_destroy_registry.register(this, underlying); + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + + constructor(ptr, selfEdge) { + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + UnitsConverterFactory_box_destroy_registry.register(this, this.#ptr); } - } - - static create(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XUnitsConverterFactory_create(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new UnitsConverterFactory(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - converter(arg_from, arg_to) { - return (() => { - const option_ptr = wasm.ICU4XUnitsConverterFactory_converter(this.underlying, arg_from.underlying, arg_to.underlying); - return (option_ptr == 0) ? undefined : new UnitsConverter(option_ptr, true, []); - })(); - } - - parser() { - return new MeasureUnitParser(wasm.ICU4XUnitsConverterFactory_parser(this.underlying), true, [this]); - } -} + + get ffiValue() { + return this.#ptr; + } + + + static create(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XUnitsConverterFactory_create(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new UnitsConverterFactory(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + converter(from, to) { + const result = wasm.ICU4XUnitsConverterFactory_converter(this.ffiValue, from.ffiValue, to.ffiValue); + + try { + + return result == 0 ? null : new UnitsConverter(result, []); + } finally { + + } + } + + parser() { + + // This lifetime edge depends on lifetimes 'a + let aEdges = [this]; + const result = wasm.ICU4XUnitsConverterFactory_parser(this.ffiValue); + + try { + + return new MeasureUnitParser(result, [], aEdges); + } finally { + + } + } + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/WeekCalculator.d.ts b/ffi/capi/bindings/js/WeekCalculator.d.ts index f1c919b8608..492b9392ef9 100644 --- a/ffi/capi/bindings/js/WeekCalculator.d.ts +++ b/ffi/capi/bindings/js/WeekCalculator.d.ts @@ -1,53 +1,31 @@ -import { u8 } from "./diplomat-runtime" -import { FFIError } from "./diplomat-runtime" -import { DataError } from "./DataError"; -import { DataProvider } from "./DataProvider"; -import { IsoWeekday } from "./IsoWeekday"; -import { Locale } from "./Locale"; -import { WeekendContainsDay } from "./WeekendContainsDay"; - -/** - - * A Week calculator, useful to be passed in to `week_of_year()` on Date and DateTime types - - * See the {@link https://docs.rs/icu/latest/icu/calendar/week/struct.WeekCalculator.html Rust documentation for `WeekCalculator`} for more information. - */ +// generated by diplomat-tool +import type { DataProvider } from "./DataProvider" +import type { IsoWeekday } from "./IsoWeekday" +import type { Locale } from "./Locale" +import type { WeekendContainsDay } from "./WeekendContainsDay" +import type { pointer, char } from "./diplomat-runtime.d.ts"; + + +/** A Week calculator, useful to be passed in to `week_of_year()` on Date and DateTime types +* +*See the [Rust documentation for `WeekCalculator`](https://docs.rs/icu/latest/icu/calendar/week/struct.WeekCalculator.html) for more information. +*/ export class WeekCalculator { + - /** - - * Creates a new {@link WeekCalculator `WeekCalculator`} from locale data. - - * See the {@link https://docs.rs/icu/latest/icu/calendar/week/struct.WeekCalculator.html#method.try_new Rust documentation for `try_new`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static create(provider: DataProvider, locale: Locale): WeekCalculator | never; - - /** - - * Additional information: {@link https://docs.rs/icu/latest/icu/calendar/week/struct.WeekCalculator.html#structfield.first_weekday 1}, {@link https://docs.rs/icu/latest/icu/calendar/week/struct.WeekCalculator.html#structfield.min_week_days 2} - */ - static create_from_first_day_of_week_and_min_week_days(first_weekday: IsoWeekday, min_week_days: u8): WeekCalculator; + get ffiValue(): pointer; - /** - * Returns the weekday that starts the week for this object's locale + static create(provider: DataProvider, locale: Locale): WeekCalculator; - * See the {@link https://docs.rs/icu/latest/icu/calendar/week/struct.WeekCalculator.html#structfield.first_weekday Rust documentation for `first_weekday`} for more information. - */ - first_weekday(): IsoWeekday; + static createFromFirstDayOfWeekAndMinWeekDays(firstWeekday: IsoWeekday, minWeekDays: number): WeekCalculator; - /** + get firstWeekday(): IsoWeekday; - * The minimum number of days overlapping a year required for a week to be considered part of that year + get minWeekDays(): number; - * See the {@link https://docs.rs/icu/latest/icu/calendar/week/struct.WeekCalculator.html#structfield.min_week_days Rust documentation for `min_week_days`} for more information. - */ - min_week_days(): u8; + get weekend(): WeekendContainsDay; - /** + - * See the {@link https://docs.rs/icu/latest/icu/calendar/week/struct.WeekCalculator.html#method.weekend Rust documentation for `weekend`} for more information. - */ - weekend(): WeekendContainsDay; -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/WeekCalculator.mjs b/ffi/capi/bindings/js/WeekCalculator.mjs index e1519f3a01a..7d6417b4755 100644 --- a/ffi/capi/bindings/js/WeekCalculator.mjs +++ b/ffi/capi/bindings/js/WeekCalculator.mjs @@ -1,59 +1,110 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" -import { DataError_js_to_rust, DataError_rust_to_js } from "./DataError.mjs" -import { IsoWeekday_js_to_rust, IsoWeekday_rust_to_js } from "./IsoWeekday.mjs" +// generated by diplomat-tool +import { DataError } from "./DataError.mjs" +import { DataProvider } from "./DataProvider.mjs" +import { IsoWeekday } from "./IsoWeekday.mjs" +import { Locale } from "./Locale.mjs" import { WeekendContainsDay } from "./WeekendContainsDay.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -const WeekCalculator_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XWeekCalculator_destroy(underlying); -}); +/** A Week calculator, useful to be passed in to `week_of_year()` on Date and DateTime types +* +*See the [Rust documentation for `WeekCalculator`](https://docs.rs/icu/latest/icu/calendar/week/struct.WeekCalculator.html) for more information. +*/ + +const WeekCalculator_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XWeekCalculator_destroy(ptr); +}); export class WeekCalculator { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - WeekCalculator_box_destroy_registry.register(this, underlying); + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + + constructor(ptr, selfEdge) { + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + WeekCalculator_box_destroy_registry.register(this, this.#ptr); + } + + get ffiValue() { + return this.#ptr; } - } - - static create(arg_provider, arg_locale) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XWeekCalculator_create(diplomat_receive_buffer, arg_provider.underlying, arg_locale.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new WeekCalculator(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - - static create_from_first_day_of_week_and_min_week_days(arg_first_weekday, arg_min_week_days) { - return new WeekCalculator(wasm.ICU4XWeekCalculator_create_from_first_day_of_week_and_min_week_days(IsoWeekday_js_to_rust[arg_first_weekday], arg_min_week_days), true, []); - } - - first_weekday() { - return IsoWeekday_rust_to_js[wasm.ICU4XWeekCalculator_first_weekday(this.underlying)]; - } - - min_week_days() { - return wasm.ICU4XWeekCalculator_min_week_days(this.underlying); - } - - weekend() { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(7, 1); - wasm.ICU4XWeekCalculator_weekend(diplomat_receive_buffer, this.underlying); - const out = new WeekendContainsDay(diplomat_receive_buffer); - wasm.diplomat_free(diplomat_receive_buffer, 7, 1); - return out; - })(); - } -} + + + static create(provider, locale) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XWeekCalculator_create(diplomat_receive_buffer, provider.ffiValue, locale.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new WeekCalculator(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static createFromFirstDayOfWeekAndMinWeekDays(firstWeekday, minWeekDays) { + const result = wasm.ICU4XWeekCalculator_create_from_first_day_of_week_and_min_week_days(firstWeekday.ffiValue, minWeekDays); + + try { + + return new WeekCalculator(result, []); + } finally { + + } + } + + get firstWeekday() { + const result = wasm.ICU4XWeekCalculator_first_weekday(this.ffiValue); + + try { + + return (() => {for (let i of IsoWeekday.values) { if(i[1] === result) return IsoWeekday[i[0]]; } return null;})(); + } finally { + + } + } + + get minWeekDays() { + const result = wasm.ICU4XWeekCalculator_min_week_days(this.ffiValue); + + try { + + return result; + } finally { + + } + } + + get weekend() { + + const diplomat_receive_buffer = wasm.diplomat_alloc(7, 1); + const result = wasm.ICU4XWeekCalculator_weekend(diplomat_receive_buffer, this.ffiValue); + + try { + + return new WeekendContainsDay()._fromFFI(diplomat_receive_buffer); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 7, 1); + + } + } + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/WeekOf.d.ts b/ffi/capi/bindings/js/WeekOf.d.ts index 005b6905ac0..54df2523e64 100644 --- a/ffi/capi/bindings/js/WeekOf.d.ts +++ b/ffi/capi/bindings/js/WeekOf.d.ts @@ -1,11 +1,16 @@ -import { u16 } from "./diplomat-runtime" -import { WeekRelativeUnit } from "./WeekRelativeUnit"; +// generated by diplomat-tool +import type { WeekRelativeUnit } from "./WeekRelativeUnit" +import type { pointer, char } from "./diplomat-runtime.d.ts"; -/** - * See the {@link https://docs.rs/icu/latest/icu/calendar/week/struct.WeekOf.html Rust documentation for `WeekOf`} for more information. - */ +/** See the [Rust documentation for `WeekOf`](https://docs.rs/icu/latest/icu/calendar/week/struct.WeekOf.html) for more information. +*/ export class WeekOf { - week: u16; - unit: WeekRelativeUnit; -} + get week() : number; + + get unit() : WeekRelativeUnit; + + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/WeekOf.mjs b/ffi/capi/bindings/js/WeekOf.mjs index e71b0cd4b8f..bfcd742060c 100644 --- a/ffi/capi/bindings/js/WeekOf.mjs +++ b/ffi/capi/bindings/js/WeekOf.mjs @@ -1,10 +1,50 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" -import { WeekRelativeUnit_js_to_rust, WeekRelativeUnit_rust_to_js } from "./WeekRelativeUnit.mjs" +// 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 { - constructor(underlying) { - this.week = (new Uint16Array(wasm.memory.buffer, underlying, 1))[0]; - this.unit = WeekRelativeUnit_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, underlying + 4)]; - } -} + #week; + get week() { + return this.#week; + } + + #unit; + get unit() { + return this.#unit; + } + + + // Return this struct in FFI function friendly format. + // Returns an array that can be expanded with spread syntax (...) + + _intoFFI( + slice_cleanup_callbacks, + appendArrayMap + ) { + return [this.#week, this.#unit.ffiValue] + } + + // 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. + _fromFFI(ptr) { + const weekDeref = (new Uint16Array(wasm.memory.buffer, ptr, 1))[0]; + this.#week = weekDeref; + const unitDeref = diplomatRuntime.enumDiscriminant(wasm, ptr + 4); + this.#unit = WeekRelativeUnit[Array.from(WeekRelativeUnit.values.keys())[unitDeref]]; + + return this; + } + // This is an out struct. You need to call other methods to be able to get this struct. + constructor(ptr) { + this._fromFFI(ptr); + } + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/WeekRelativeUnit.d.ts b/ffi/capi/bindings/js/WeekRelativeUnit.d.ts index 9d326b42ac1..3470a3def8c 100644 --- a/ffi/capi/bindings/js/WeekRelativeUnit.d.ts +++ b/ffi/capi/bindings/js/WeekRelativeUnit.d.ts @@ -1,16 +1,23 @@ +// generated by diplomat-tool +import type { pointer, char } from "./diplomat-runtime.d.ts"; + +// Base enumerator definition +/** See the [Rust documentation for `RelativeUnit`](https://docs.rs/icu/latest/icu/calendar/week/enum.RelativeUnit.html) for more information. +*/ +export class WeekRelativeUnit { + constructor(value : WeekRelativeUnit | string); + + get value() : string; + + get ffiValue() : number; + + static Previous : WeekRelativeUnit; + + static Current : WeekRelativeUnit; + + static Next : WeekRelativeUnit; + + + -/** - - * See the {@link https://docs.rs/icu/latest/icu/calendar/week/enum.RelativeUnit.html Rust documentation for `RelativeUnit`} for more information. - */ -export enum WeekRelativeUnit { - /** - */ - Previous = 'Previous', - /** - */ - Current = 'Current', - /** - */ - Next = 'Next', } \ No newline at end of file diff --git a/ffi/capi/bindings/js/WeekRelativeUnit.mjs b/ffi/capi/bindings/js/WeekRelativeUnit.mjs index 1d8839539a1..79667a98e7f 100644 --- a/ffi/capi/bindings/js/WeekRelativeUnit.mjs +++ b/ffi/capi/bindings/js/WeekRelativeUnit.mjs @@ -1,20 +1,47 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" - -export const WeekRelativeUnit_js_to_rust = { - "Previous": 0, - "Current": 1, - "Next": 2, -}; - -export const WeekRelativeUnit_rust_to_js = { - [0]: "Previous", - [1]: "Current", - [2]: "Next", -}; - -export const WeekRelativeUnit = { - "Previous": "Previous", - "Current": "Current", - "Next": "Next", -}; +// generated by diplomat-tool +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; + +// Base enumerator definition +/** See the [Rust documentation for `RelativeUnit`](https://docs.rs/icu/latest/icu/calendar/week/enum.RelativeUnit.html) for more information. +*/ +export class WeekRelativeUnit { + #value = undefined; + + static values = new Map([ + ["Previous", 0], + ["Current", 1], + ["Next", 2] + ]); + constructor(value) { + if (value instanceof WeekRelativeUnit) { + this.#value = value.value; + return; + } + + if (WeekRelativeUnit.values.has(value)) { + this.#value = value; + return; + } + + throw TypeError(value + " is not a WeekRelativeUnit and does not correspond to any of its enumerator values."); + } + + get value() { + return this.#value; + } + + get ffiValue() { + return WeekRelativeUnit.values.get(this.#value); + } + + static Previous = new WeekRelativeUnit("Previous"); + + static Current = new WeekRelativeUnit("Current"); + + static Next = new WeekRelativeUnit("Next"); + + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/WeekendContainsDay.d.ts b/ffi/capi/bindings/js/WeekendContainsDay.d.ts index 80b781195e6..7351cfe3b89 100644 --- a/ffi/capi/bindings/js/WeekendContainsDay.d.ts +++ b/ffi/capi/bindings/js/WeekendContainsDay.d.ts @@ -1,16 +1,27 @@ +// generated by diplomat-tool +import type { pointer, char } from "./diplomat-runtime.d.ts"; -/** - * Documents which days of the week are considered to be a part of the weekend - - * See the {@link https://docs.rs/icu/latest/icu/calendar/week/struct.WeekCalculator.html#method.weekend Rust documentation for `weekend`} for more information. - */ +/** Documents which days of the week are considered to be a part of the weekend +* +*See the [Rust documentation for `weekend`](https://docs.rs/icu/latest/icu/calendar/week/struct.WeekCalculator.html#method.weekend) for more information. +*/ export class WeekendContainsDay { - monday: boolean; - tuesday: boolean; - wednesday: boolean; - thursday: boolean; - friday: boolean; - saturday: boolean; - sunday: boolean; -} + get monday() : boolean; + set monday(value: boolean); + get tuesday() : boolean; + set tuesday(value: boolean); + get wednesday() : boolean; + set wednesday(value: boolean); + get thursday() : boolean; + set thursday(value: boolean); + get friday() : boolean; + set friday(value: boolean); + get saturday() : boolean; + set saturday(value: boolean); + get sunday() : boolean; + set sunday(value: boolean); + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/WeekendContainsDay.mjs b/ffi/capi/bindings/js/WeekendContainsDay.mjs index f229fb7e2f2..b98dc557cc9 100644 --- a/ffi/capi/bindings/js/WeekendContainsDay.mjs +++ b/ffi/capi/bindings/js/WeekendContainsDay.mjs @@ -1,14 +1,96 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" +// generated by diplomat-tool +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; + +/** Documents which days of the week are considered to be a part of the weekend +* +*See the [Rust documentation for `weekend`](https://docs.rs/icu/latest/icu/calendar/week/struct.WeekCalculator.html#method.weekend) for more information. +*/ export class WeekendContainsDay { - constructor(underlying) { - this.monday = (new Uint8Array(wasm.memory.buffer, underlying, 1))[0] == 1; - this.tuesday = (new Uint8Array(wasm.memory.buffer, underlying + 1, 1))[0] == 1; - this.wednesday = (new Uint8Array(wasm.memory.buffer, underlying + 2, 1))[0] == 1; - this.thursday = (new Uint8Array(wasm.memory.buffer, underlying + 3, 1))[0] == 1; - this.friday = (new Uint8Array(wasm.memory.buffer, underlying + 4, 1))[0] == 1; - this.saturday = (new Uint8Array(wasm.memory.buffer, underlying + 5, 1))[0] == 1; - this.sunday = (new Uint8Array(wasm.memory.buffer, underlying + 6, 1))[0] == 1; - } -} + #monday; + get monday() { + return this.#monday; + } + set monday(value) { + this.#monday = value; + } + #tuesday; + get tuesday() { + return this.#tuesday; + } + set tuesday(value) { + this.#tuesday = value; + } + #wednesday; + get wednesday() { + return this.#wednesday; + } + set wednesday(value) { + this.#wednesday = value; + } + #thursday; + get thursday() { + return this.#thursday; + } + set thursday(value) { + this.#thursday = value; + } + #friday; + get friday() { + return this.#friday; + } + set friday(value) { + this.#friday = value; + } + #saturday; + get saturday() { + return this.#saturday; + } + set saturday(value) { + this.#saturday = value; + } + #sunday; + get sunday() { + return this.#sunday; + } + set sunday(value) { + this.#sunday = value; + } + + // Return this struct in FFI function friendly format. + // Returns an array that can be expanded with spread syntax (...) + + _intoFFI( + slice_cleanup_callbacks, + appendArrayMap + ) { + return [this.#monday, this.#tuesday, this.#wednesday, this.#thursday, this.#friday, this.#saturday, this.#sunday] + } + + // 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. + _fromFFI(ptr) { + const mondayDeref = (new Uint8Array(wasm.memory.buffer, ptr, 1))[0] == 1; + this.#monday = mondayDeref; + const tuesdayDeref = (new Uint8Array(wasm.memory.buffer, ptr + 1, 1))[0] == 1; + this.#tuesday = tuesdayDeref; + const wednesdayDeref = (new Uint8Array(wasm.memory.buffer, ptr + 2, 1))[0] == 1; + this.#wednesday = wednesdayDeref; + const thursdayDeref = (new Uint8Array(wasm.memory.buffer, ptr + 3, 1))[0] == 1; + this.#thursday = thursdayDeref; + const fridayDeref = (new Uint8Array(wasm.memory.buffer, ptr + 4, 1))[0] == 1; + this.#friday = fridayDeref; + const saturdayDeref = (new Uint8Array(wasm.memory.buffer, ptr + 5, 1))[0] == 1; + this.#saturday = saturdayDeref; + const sundayDeref = (new Uint8Array(wasm.memory.buffer, ptr + 6, 1))[0] == 1; + this.#sunday = sundayDeref; + + return this; + } + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/WordBreakIteratorLatin1.d.ts b/ffi/capi/bindings/js/WordBreakIteratorLatin1.d.ts index 6b106648a6e..cbe345d0f26 100644 --- a/ffi/capi/bindings/js/WordBreakIteratorLatin1.d.ts +++ b/ffi/capi/bindings/js/WordBreakIteratorLatin1.d.ts @@ -1,33 +1,22 @@ -import { i32 } from "./diplomat-runtime" -import { SegmenterWordType } from "./SegmenterWordType"; +// generated by diplomat-tool +import type { SegmenterWordType } from "./SegmenterWordType" +import type { pointer, char } from "./diplomat-runtime.d.ts"; -/** - * See the {@link https://docs.rs/icu/latest/icu/segmenter/struct.WordBreakIterator.html Rust documentation for `WordBreakIterator`} for more information. - */ +/** See the [Rust documentation for `WordBreakIterator`](https://docs.rs/icu/latest/icu/segmenter/struct.WordBreakIterator.html) for more information. +*/ export class WordBreakIteratorLatin1 { + - /** + get ffiValue(): pointer; - * Finds the next breakpoint. Returns -1 if at the end of the string or if the index is out of range of a 32-bit signed integer. - * See the {@link https://docs.rs/icu/latest/icu/segmenter/struct.WordBreakIterator.html#method.next Rust documentation for `next`} for more information. - */ - next(): i32; + next(): number; - /** + get wordType(): SegmenterWordType; - * Return the status value of break boundary. + get isWordLike(): boolean; - * See the {@link https://docs.rs/icu/latest/icu/segmenter/struct.WordBreakIterator.html#method.word_type Rust documentation for `word_type`} for more information. - */ - word_type(): SegmenterWordType; + - /** - - * Return true when break boundary is word-like such as letter/number/CJK - - * See the {@link https://docs.rs/icu/latest/icu/segmenter/struct.WordBreakIterator.html#method.is_word_like Rust documentation for `is_word_like`} for more information. - */ - is_word_like(): boolean; -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/WordBreakIteratorLatin1.mjs b/ffi/capi/bindings/js/WordBreakIteratorLatin1.mjs index 121b22d75d3..1c0de663e94 100644 --- a/ffi/capi/bindings/js/WordBreakIteratorLatin1.mjs +++ b/ffi/capi/bindings/js/WordBreakIteratorLatin1.mjs @@ -1,30 +1,75 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" -import { SegmenterWordType_js_to_rust, SegmenterWordType_rust_to_js } from "./SegmenterWordType.mjs" +// generated by diplomat-tool +import { SegmenterWordType } from "./SegmenterWordType.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -const WordBreakIteratorLatin1_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XWordBreakIteratorLatin1_destroy(underlying); -}); +/** See the [Rust documentation for `WordBreakIterator`](https://docs.rs/icu/latest/icu/segmenter/struct.WordBreakIterator.html) for more information. +*/ + +const WordBreakIteratorLatin1_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XWordBreakIteratorLatin1_destroy(ptr); +}); export class WordBreakIteratorLatin1 { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - WordBreakIteratorLatin1_box_destroy_registry.register(this, underlying); + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + #aEdge = []; + + + constructor(ptr, selfEdge, aEdge) { + + + this.#aEdge = aEdge; + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + WordBreakIteratorLatin1_box_destroy_registry.register(this, this.#ptr); + } + + get ffiValue() { + return this.#ptr; } - } - next() { - return wasm.ICU4XWordBreakIteratorLatin1_next(this.underlying); - } - word_type() { - return SegmenterWordType_rust_to_js[wasm.ICU4XWordBreakIteratorLatin1_word_type(this.underlying)]; - } + next() { + const result = wasm.ICU4XWordBreakIteratorLatin1_next(this.ffiValue); + + try { + + return result; + } finally { + + } + } + + get wordType() { + const result = wasm.ICU4XWordBreakIteratorLatin1_word_type(this.ffiValue); + + try { + + return SegmenterWordType[Array.from(SegmenterWordType.values.keys())[result]]; + } finally { + + } + } + + get isWordLike() { + const result = wasm.ICU4XWordBreakIteratorLatin1_is_word_like(this.ffiValue); + + try { + + return result; + } finally { + + } + } + + - is_word_like() { - return wasm.ICU4XWordBreakIteratorLatin1_is_word_like(this.underlying); - } -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/WordBreakIteratorUtf16.d.ts b/ffi/capi/bindings/js/WordBreakIteratorUtf16.d.ts index 6dd2b1a023b..4c417684d9e 100644 --- a/ffi/capi/bindings/js/WordBreakIteratorUtf16.d.ts +++ b/ffi/capi/bindings/js/WordBreakIteratorUtf16.d.ts @@ -1,33 +1,22 @@ -import { i32 } from "./diplomat-runtime" -import { SegmenterWordType } from "./SegmenterWordType"; +// generated by diplomat-tool +import type { SegmenterWordType } from "./SegmenterWordType" +import type { pointer, char } from "./diplomat-runtime.d.ts"; -/** - * See the {@link https://docs.rs/icu/latest/icu/segmenter/struct.WordBreakIterator.html Rust documentation for `WordBreakIterator`} for more information. - */ +/** See the [Rust documentation for `WordBreakIterator`](https://docs.rs/icu/latest/icu/segmenter/struct.WordBreakIterator.html) for more information. +*/ export class WordBreakIteratorUtf16 { + - /** + get ffiValue(): pointer; - * Finds the next breakpoint. Returns -1 if at the end of the string or if the index is out of range of a 32-bit signed integer. - * See the {@link https://docs.rs/icu/latest/icu/segmenter/struct.WordBreakIterator.html#method.next Rust documentation for `next`} for more information. - */ - next(): i32; + next(): number; - /** + get wordType(): SegmenterWordType; - * Return the status value of break boundary. + get isWordLike(): boolean; - * See the {@link https://docs.rs/icu/latest/icu/segmenter/struct.WordBreakIterator.html#method.word_type Rust documentation for `word_type`} for more information. - */ - word_type(): SegmenterWordType; + - /** - - * Return true when break boundary is word-like such as letter/number/CJK - - * See the {@link https://docs.rs/icu/latest/icu/segmenter/struct.WordBreakIterator.html#method.is_word_like Rust documentation for `is_word_like`} for more information. - */ - is_word_like(): boolean; -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/WordBreakIteratorUtf16.mjs b/ffi/capi/bindings/js/WordBreakIteratorUtf16.mjs index 480f16467ab..6c5ea32f21e 100644 --- a/ffi/capi/bindings/js/WordBreakIteratorUtf16.mjs +++ b/ffi/capi/bindings/js/WordBreakIteratorUtf16.mjs @@ -1,30 +1,75 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" -import { SegmenterWordType_js_to_rust, SegmenterWordType_rust_to_js } from "./SegmenterWordType.mjs" +// generated by diplomat-tool +import { SegmenterWordType } from "./SegmenterWordType.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -const WordBreakIteratorUtf16_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XWordBreakIteratorUtf16_destroy(underlying); -}); +/** See the [Rust documentation for `WordBreakIterator`](https://docs.rs/icu/latest/icu/segmenter/struct.WordBreakIterator.html) for more information. +*/ + +const WordBreakIteratorUtf16_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XWordBreakIteratorUtf16_destroy(ptr); +}); export class WordBreakIteratorUtf16 { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - WordBreakIteratorUtf16_box_destroy_registry.register(this, underlying); + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + #aEdge = []; + + + constructor(ptr, selfEdge, aEdge) { + + + this.#aEdge = aEdge; + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + WordBreakIteratorUtf16_box_destroy_registry.register(this, this.#ptr); + } + + get ffiValue() { + return this.#ptr; } - } - next() { - return wasm.ICU4XWordBreakIteratorUtf16_next(this.underlying); - } - word_type() { - return SegmenterWordType_rust_to_js[wasm.ICU4XWordBreakIteratorUtf16_word_type(this.underlying)]; - } + next() { + const result = wasm.ICU4XWordBreakIteratorUtf16_next(this.ffiValue); + + try { + + return result; + } finally { + + } + } + + get wordType() { + const result = wasm.ICU4XWordBreakIteratorUtf16_word_type(this.ffiValue); + + try { + + return SegmenterWordType[Array.from(SegmenterWordType.values.keys())[result]]; + } finally { + + } + } + + get isWordLike() { + const result = wasm.ICU4XWordBreakIteratorUtf16_is_word_like(this.ffiValue); + + try { + + return result; + } finally { + + } + } + + - is_word_like() { - return wasm.ICU4XWordBreakIteratorUtf16_is_word_like(this.underlying); - } -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/WordBreakIteratorUtf8.d.ts b/ffi/capi/bindings/js/WordBreakIteratorUtf8.d.ts index 5980bd0090b..53ba7523baa 100644 --- a/ffi/capi/bindings/js/WordBreakIteratorUtf8.d.ts +++ b/ffi/capi/bindings/js/WordBreakIteratorUtf8.d.ts @@ -1,33 +1,22 @@ -import { i32 } from "./diplomat-runtime" -import { SegmenterWordType } from "./SegmenterWordType"; +// generated by diplomat-tool +import type { SegmenterWordType } from "./SegmenterWordType" +import type { pointer, char } from "./diplomat-runtime.d.ts"; -/** - * See the {@link https://docs.rs/icu/latest/icu/segmenter/struct.WordBreakIterator.html Rust documentation for `WordBreakIterator`} for more information. - */ +/** See the [Rust documentation for `WordBreakIterator`](https://docs.rs/icu/latest/icu/segmenter/struct.WordBreakIterator.html) for more information. +*/ export class WordBreakIteratorUtf8 { + - /** + get ffiValue(): pointer; - * Finds the next breakpoint. Returns -1 if at the end of the string or if the index is out of range of a 32-bit signed integer. - * See the {@link https://docs.rs/icu/latest/icu/segmenter/struct.WordBreakIterator.html#method.next Rust documentation for `next`} for more information. - */ - next(): i32; + next(): number; - /** + get wordType(): SegmenterWordType; - * Return the status value of break boundary. + get isWordLike(): boolean; - * See the {@link https://docs.rs/icu/latest/icu/segmenter/struct.WordBreakIterator.html#method.word_type Rust documentation for `word_type`} for more information. - */ - word_type(): SegmenterWordType; + - /** - - * Return true when break boundary is word-like such as letter/number/CJK - - * See the {@link https://docs.rs/icu/latest/icu/segmenter/struct.WordBreakIterator.html#method.is_word_like Rust documentation for `is_word_like`} for more information. - */ - is_word_like(): boolean; -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/WordBreakIteratorUtf8.mjs b/ffi/capi/bindings/js/WordBreakIteratorUtf8.mjs index d8f0828c2b6..157f98d29c9 100644 --- a/ffi/capi/bindings/js/WordBreakIteratorUtf8.mjs +++ b/ffi/capi/bindings/js/WordBreakIteratorUtf8.mjs @@ -1,30 +1,75 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" -import { SegmenterWordType_js_to_rust, SegmenterWordType_rust_to_js } from "./SegmenterWordType.mjs" +// generated by diplomat-tool +import { SegmenterWordType } from "./SegmenterWordType.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -const WordBreakIteratorUtf8_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XWordBreakIteratorUtf8_destroy(underlying); -}); +/** See the [Rust documentation for `WordBreakIterator`](https://docs.rs/icu/latest/icu/segmenter/struct.WordBreakIterator.html) for more information. +*/ + +const WordBreakIteratorUtf8_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XWordBreakIteratorUtf8_destroy(ptr); +}); export class WordBreakIteratorUtf8 { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - WordBreakIteratorUtf8_box_destroy_registry.register(this, underlying); + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + #aEdge = []; + + + constructor(ptr, selfEdge, aEdge) { + + + this.#aEdge = aEdge; + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + WordBreakIteratorUtf8_box_destroy_registry.register(this, this.#ptr); + } + + get ffiValue() { + return this.#ptr; } - } - next() { - return wasm.ICU4XWordBreakIteratorUtf8_next(this.underlying); - } - word_type() { - return SegmenterWordType_rust_to_js[wasm.ICU4XWordBreakIteratorUtf8_word_type(this.underlying)]; - } + next() { + const result = wasm.ICU4XWordBreakIteratorUtf8_next(this.ffiValue); + + try { + + return result; + } finally { + + } + } + + get wordType() { + const result = wasm.ICU4XWordBreakIteratorUtf8_word_type(this.ffiValue); + + try { + + return SegmenterWordType[Array.from(SegmenterWordType.values.keys())[result]]; + } finally { + + } + } + + get isWordLike() { + const result = wasm.ICU4XWordBreakIteratorUtf8_is_word_like(this.ffiValue); + + try { + + return result; + } finally { + + } + } + + - is_word_like() { - return wasm.ICU4XWordBreakIteratorUtf8_is_word_like(this.underlying); - } -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/WordSegmenter.d.ts b/ffi/capi/bindings/js/WordSegmenter.d.ts index 953355394b4..738bf9ddbd1 100644 --- a/ffi/capi/bindings/js/WordSegmenter.d.ts +++ b/ffi/capi/bindings/js/WordSegmenter.d.ts @@ -1,74 +1,27 @@ -import { FFIError } from "./diplomat-runtime" -import { DataError } from "./DataError"; -import { DataProvider } from "./DataProvider"; -import { WordBreakIteratorLatin1 } from "./WordBreakIteratorLatin1"; -import { WordBreakIteratorUtf16 } from "./WordBreakIteratorUtf16"; -import { WordBreakIteratorUtf8 } from "./WordBreakIteratorUtf8"; +// generated by diplomat-tool +import type { DataProvider } from "./DataProvider" +import type { WordBreakIteratorUtf16 } from "./WordBreakIteratorUtf16" +import type { pointer, char } from "./diplomat-runtime.d.ts"; -/** - * An ICU4X word-break segmenter, capable of finding word breakpoints in strings. - - * See the {@link https://docs.rs/icu/latest/icu/segmenter/struct.WordSegmenter.html Rust documentation for `WordSegmenter`} for more information. - */ +/** An ICU4X word-break segmenter, capable of finding word breakpoints in strings. +* +*See the [Rust documentation for `WordSegmenter`](https://docs.rs/icu/latest/icu/segmenter/struct.WordSegmenter.html) for more information. +*/ export class WordSegmenter { + - /** - - * Construct an {@link WordSegmenter `WordSegmenter`} with automatically selecting the best available LSTM or dictionary payload data. - - * Note: currently, it uses dictionary for Chinese and Japanese, and LSTM for Burmese, Khmer, Lao, and Thai. - - * See the {@link https://docs.rs/icu/latest/icu/segmenter/struct.WordSegmenter.html#method.new_auto Rust documentation for `new_auto`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static create_auto(provider: DataProvider): WordSegmenter | never; - - /** - - * Construct an {@link WordSegmenter `WordSegmenter`} with LSTM payload data for Burmese, Khmer, Lao, and Thai. - - * Warning: {@link WordSegmenter `WordSegmenter`} created by this function doesn't handle Chinese or Japanese. - - * See the {@link https://docs.rs/icu/latest/icu/segmenter/struct.WordSegmenter.html#method.new_lstm Rust documentation for `new_lstm`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static create_lstm(provider: DataProvider): WordSegmenter | never; - - /** - - * Construct an {@link WordSegmenter `WordSegmenter`} with dictionary payload data for Chinese, Japanese, Burmese, Khmer, Lao, and Thai. - - * See the {@link https://docs.rs/icu/latest/icu/segmenter/struct.WordSegmenter.html#method.new_dictionary Rust documentation for `new_dictionary`} for more information. - * @throws {@link FFIError}<{@link DataError}> - */ - static create_dictionary(provider: DataProvider): WordSegmenter | never; - - /** - - * Segments a string. - - * Ill-formed input is treated as if errors had been replaced with REPLACEMENT CHARACTERs according to the WHATWG Encoding Standard. - - * See the {@link https://docs.rs/icu/latest/icu/segmenter/struct.WordSegmenter.html#method.segment_utf8 Rust documentation for `segment_utf8`} for more information. - */ - segment_utf8(input: string): WordBreakIteratorUtf8; + get ffiValue(): pointer; - /** - * Segments a string. + static createAuto(provider: DataProvider): WordSegmenter; - * Ill-formed input is treated as if errors had been replaced with REPLACEMENT CHARACTERs according to the WHATWG Encoding Standard. + static createLstm(provider: DataProvider): WordSegmenter; - * See the {@link https://docs.rs/icu/latest/icu/segmenter/struct.WordSegmenter.html#method.segment_utf16 Rust documentation for `segment_utf16`} for more information. - */ - segment_utf16(input: string): WordBreakIteratorUtf16; + static createDictionary(provider: DataProvider): WordSegmenter; - /** + segment(input: string): WordBreakIteratorUtf16; - * Segments a Latin-1 string. + - * See the {@link https://docs.rs/icu/latest/icu/segmenter/struct.WordSegmenter.html#method.segment_latin1 Rust documentation for `segment_latin1`} for more information. - */ - segment_latin1(input: Uint8Array): WordBreakIteratorLatin1; -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/WordSegmenter.mjs b/ffi/capi/bindings/js/WordSegmenter.mjs index 94f5f36f64c..2287a1bd267 100644 --- a/ffi/capi/bindings/js/WordSegmenter.mjs +++ b/ffi/capi/bindings/js/WordSegmenter.mjs @@ -1,93 +1,116 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" -import { DataError_js_to_rust, DataError_rust_to_js } from "./DataError.mjs" -import { WordBreakIteratorLatin1 } from "./WordBreakIteratorLatin1.mjs" +// generated by diplomat-tool +import { DataError } from "./DataError.mjs" +import { DataProvider } from "./DataProvider.mjs" import { WordBreakIteratorUtf16 } from "./WordBreakIteratorUtf16.mjs" -import { WordBreakIteratorUtf8 } from "./WordBreakIteratorUtf8.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -const WordSegmenter_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XWordSegmenter_destroy(underlying); -}); +/** An ICU4X word-break segmenter, capable of finding word breakpoints in strings. +* +*See the [Rust documentation for `WordSegmenter`](https://docs.rs/icu/latest/icu/segmenter/struct.WordSegmenter.html) for more information. +*/ + +const WordSegmenter_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XWordSegmenter_destroy(ptr); +}); export class WordSegmenter { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - WordSegmenter_box_destroy_registry.register(this, underlying); + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + + constructor(ptr, selfEdge) { + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + WordSegmenter_box_destroy_registry.register(this, this.#ptr); } - } - static create_auto(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XWordSegmenter_create_auto(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new WordSegmenter(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } + get ffiValue() { + return this.#ptr; + } - static create_lstm(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XWordSegmenter_create_lstm(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new WordSegmenter(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - static create_dictionary(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XWordSegmenter_create_dictionary(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new WordSegmenter(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = DataError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } + static createAuto(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XWordSegmenter_create_auto(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new WordSegmenter(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } - segment_utf8(arg_input) { - const buf_arg_input = diplomatRuntime.DiplomatBuf.str8(wasm, arg_input); - const diplomat_out = new WordBreakIteratorUtf8(wasm.ICU4XWordSegmenter_segment_utf8(this.underlying, buf_arg_input.ptr, buf_arg_input.size), true, [this, buf_arg_input]); - buf_arg_input.garbageCollect(); - return diplomat_out; - } + static createLstm(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XWordSegmenter_create_lstm(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new WordSegmenter(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + static createDictionary(provider) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + const result = wasm.ICU4XWordSegmenter_create_dictionary(diplomat_receive_buffer, provider.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]]; + throw new Error('DataError: ' + cause.value, { cause }); + } + return new WordSegmenter(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + } + } + + segment(input) { + + const inputSlice = diplomatRuntime.DiplomatBuf.str16(wasm, input); + + // This lifetime edge depends on lifetimes 'a + let aEdges = [this, inputSlice]; + const result = wasm.ICU4XWordSegmenter_segment_utf16(this.ffiValue, inputSlice.ptr, inputSlice.size); + + try { + + return new WordBreakIteratorUtf16(result, [], aEdges); + } finally { + + inputSlice.garbageCollect(); + + } + } - segment_utf16(arg_input) { - const buf_arg_input = diplomatRuntime.DiplomatBuf.str16(wasm, arg_input); - const diplomat_out = new WordBreakIteratorUtf16(wasm.ICU4XWordSegmenter_segment_utf16(this.underlying, buf_arg_input.ptr, buf_arg_input.size), true, [this, buf_arg_input]); - buf_arg_input.garbageCollect(); - return diplomat_out; - } + - segment_latin1(arg_input) { - const buf_arg_input = diplomatRuntime.DiplomatBuf.slice(wasm, arg_input, "u8"); - const diplomat_out = new WordBreakIteratorLatin1(wasm.ICU4XWordSegmenter_segment_latin1(this.underlying, buf_arg_input.ptr, buf_arg_input.size), true, [this, buf_arg_input]); - buf_arg_input.garbageCollect(); - return diplomat_out; - } -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/ZonedDateTimeFormatter.d.ts b/ffi/capi/bindings/js/ZonedDateTimeFormatter.d.ts index ae3689f62dd..a0e3f638c17 100644 --- a/ffi/capi/bindings/js/ZonedDateTimeFormatter.d.ts +++ b/ffi/capi/bindings/js/ZonedDateTimeFormatter.d.ts @@ -1,59 +1,33 @@ -import { FFIError } from "./diplomat-runtime" -import { CustomTimeZone } from "./CustomTimeZone"; -import { DataProvider } from "./DataProvider"; -import { DateLength } from "./DateLength"; -import { DateTime } from "./DateTime"; -import { Error } from "./Error"; -import { IsoDateTime } from "./IsoDateTime"; -import { IsoTimeZoneOptions } from "./IsoTimeZoneOptions"; -import { Locale } from "./Locale"; -import { TimeLength } from "./TimeLength"; - -/** - - * An object capable of formatting a date time with time zone to a string. - - * See the {@link https://docs.rs/icu/latest/icu/datetime/struct.ZonedDateTimeFormatter.html Rust documentation for `ZonedDateTimeFormatter`} for more information. - */ +// generated by diplomat-tool +import type { CustomTimeZone } from "./CustomTimeZone" +import type { DataProvider } from "./DataProvider" +import type { DateLength } from "./DateLength" +import type { DateTime } from "./DateTime" +import type { IsoDateTime } from "./IsoDateTime" +import type { IsoTimeZoneOptions } from "./IsoTimeZoneOptions" +import type { Locale } from "./Locale" +import type { TimeLength } from "./TimeLength" +import type { pointer, char } from "./diplomat-runtime.d.ts"; + + +/** An object capable of formatting a date time with time zone to a string. +* +*See the [Rust documentation for `ZonedDateTimeFormatter`](https://docs.rs/icu/latest/icu/datetime/struct.ZonedDateTimeFormatter.html) for more information. +*/ export class ZonedDateTimeFormatter { + - /** + get ffiValue(): pointer; - * Creates a new {@link ZonedDateTimeFormatter `ZonedDateTimeFormatter`} from locale data. - * This function has `date_length` and `time_length` arguments and uses default options for the time zone. + static createWithLengths(provider: DataProvider, locale: Locale, dateLength: DateLength, timeLength: TimeLength): ZonedDateTimeFormatter; - * See the {@link https://docs.rs/icu/latest/icu/datetime/struct.ZonedDateTimeFormatter.html#method.try_new Rust documentation for `try_new`} for more information. - * @throws {@link FFIError}<{@link Error}> - */ - static create_with_lengths(provider: DataProvider, locale: Locale, date_length: DateLength, time_length: TimeLength): ZonedDateTimeFormatter | never; + static createWithLengthsAndIso8601TimeZoneFallback(provider: DataProvider, locale: Locale, dateLength: DateLength, timeLength: TimeLength, zoneOptions: IsoTimeZoneOptions): ZonedDateTimeFormatter; - /** + formatDatetimeWithCustomTimeZone(datetime: DateTime, timeZone: CustomTimeZone): string; - * Creates a new {@link ZonedDateTimeFormatter `ZonedDateTimeFormatter`} from locale data. + formatIsoDatetimeWithCustomTimeZone(datetime: IsoDateTime, timeZone: CustomTimeZone): string; - * This function has `date_length` and `time_length` arguments and uses an ISO-8601 style fallback for the time zone with the given configurations. + - * See the {@link https://docs.rs/icu/latest/icu/datetime/struct.ZonedDateTimeFormatter.html#method.try_new Rust documentation for `try_new`} for more information. - * @throws {@link FFIError}<{@link Error}> - */ - static create_with_lengths_and_iso_8601_time_zone_fallback(provider: DataProvider, locale: Locale, date_length: DateLength, time_length: TimeLength, zone_options: IsoTimeZoneOptions): ZonedDateTimeFormatter | never; - - /** - - * Formats a {@link DateTime `DateTime`} and {@link CustomTimeZone `CustomTimeZone`} to a string. - - * See the {@link https://docs.rs/icu/latest/icu/datetime/struct.ZonedDateTimeFormatter.html#method.format Rust documentation for `format`} for more information. - * @throws {@link FFIError}<{@link Error}> - */ - format_datetime_with_custom_time_zone(datetime: DateTime, time_zone: CustomTimeZone): string | never; - - /** - - * Formats a {@link IsoDateTime `IsoDateTime`} and {@link CustomTimeZone `CustomTimeZone`} to a string. - - * See the {@link https://docs.rs/icu/latest/icu/datetime/struct.ZonedDateTimeFormatter.html#method.format Rust documentation for `format`} for more information. - * @throws {@link FFIError}<{@link Error}> - */ - format_iso_datetime_with_custom_time_zone(datetime: IsoDateTime, time_zone: CustomTimeZone): string | never; -} +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/ZonedDateTimeFormatter.mjs b/ffi/capi/bindings/js/ZonedDateTimeFormatter.mjs index 4a6187eb583..faff2ce8dcc 100644 --- a/ffi/capi/bindings/js/ZonedDateTimeFormatter.mjs +++ b/ffi/capi/bindings/js/ZonedDateTimeFormatter.mjs @@ -1,98 +1,137 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.mjs" -import { DateLength_js_to_rust, DateLength_rust_to_js } from "./DateLength.mjs" -import { Error_js_to_rust, Error_rust_to_js } from "./Error.mjs" -import { IsoTimeZoneFormat_js_to_rust, IsoTimeZoneFormat_rust_to_js } from "./IsoTimeZoneFormat.mjs" -import { IsoTimeZoneMinuteDisplay_js_to_rust, IsoTimeZoneMinuteDisplay_rust_to_js } from "./IsoTimeZoneMinuteDisplay.mjs" -import { IsoTimeZoneSecondDisplay_js_to_rust, IsoTimeZoneSecondDisplay_rust_to_js } from "./IsoTimeZoneSecondDisplay.mjs" -import { TimeLength_js_to_rust, TimeLength_rust_to_js } from "./TimeLength.mjs" +// generated by diplomat-tool +import { CustomTimeZone } from "./CustomTimeZone.mjs" +import { DataProvider } from "./DataProvider.mjs" +import { DateLength } from "./DateLength.mjs" +import { DateTime } from "./DateTime.mjs" +import { Error } from "./Error.mjs" +import { IsoDateTime } from "./IsoDateTime.mjs" +import { IsoTimeZoneOptions } from "./IsoTimeZoneOptions.mjs" +import { Locale } from "./Locale.mjs" +import { TimeLength } from "./TimeLength.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; -const ZonedDateTimeFormatter_box_destroy_registry = new FinalizationRegistry(underlying => { - wasm.ICU4XZonedDateTimeFormatter_destroy(underlying); -}); +/** An object capable of formatting a date time with time zone to a string. +* +*See the [Rust documentation for `ZonedDateTimeFormatter`](https://docs.rs/icu/latest/icu/datetime/struct.ZonedDateTimeFormatter.html) for more information. +*/ + +const ZonedDateTimeFormatter_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.ICU4XZonedDateTimeFormatter_destroy(ptr); +}); export class ZonedDateTimeFormatter { - #lifetimeEdges = []; - constructor(underlying, owned, edges) { - this.underlying = underlying; - this.#lifetimeEdges.push(...edges); - if (owned) { - ZonedDateTimeFormatter_box_destroy_registry.register(this, underlying); + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + + constructor(ptr, selfEdge) { + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + // Unconditionally register to destroy when this object is ready to garbage collect. + ZonedDateTimeFormatter_box_destroy_registry.register(this, this.#ptr); } - } - static create_with_lengths(arg_provider, arg_locale, arg_date_length, arg_time_length) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XZonedDateTimeFormatter_create_with_lengths(diplomat_receive_buffer, arg_provider.underlying, arg_locale.underlying, DateLength_js_to_rust[arg_date_length], TimeLength_js_to_rust[arg_time_length]); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new ZonedDateTimeFormatter(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = Error_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } + get ffiValue() { + return this.#ptr; + } - static create_with_lengths_and_iso_8601_time_zone_fallback(arg_provider, arg_locale, arg_date_length, arg_time_length, arg_zone_options) { - const field_format_arg_zone_options = arg_zone_options["format"]; - const field_minutes_arg_zone_options = arg_zone_options["minutes"]; - const field_seconds_arg_zone_options = arg_zone_options["seconds"]; - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XZonedDateTimeFormatter_create_with_lengths_and_iso_8601_time_zone_fallback(diplomat_receive_buffer, arg_provider.underlying, arg_locale.underlying, DateLength_js_to_rust[arg_date_length], TimeLength_js_to_rust[arg_time_length], IsoTimeZoneFormat_js_to_rust[field_format_arg_zone_options], IsoTimeZoneMinuteDisplay_js_to_rust[field_minutes_arg_zone_options], IsoTimeZoneSecondDisplay_js_to_rust[field_seconds_arg_zone_options]); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new ZonedDateTimeFormatter(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = Error_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - format_datetime_with_custom_time_zone(arg_datetime, arg_time_zone) { - return diplomatRuntime.withDiplomatWrite(wasm, (write) => { - return (() => { + static createWithLengths(provider, locale, dateLength, timeLength) { + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XZonedDateTimeFormatter_format_datetime_with_custom_time_zone(diplomat_receive_buffer, this.underlying, arg_datetime.underlying, arg_time_zone.underlying, write); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = {}; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = Error_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); + const result = wasm.ICU4XZonedDateTimeFormatter_create_with_lengths(diplomat_receive_buffer, provider.ffiValue, locale.ffiValue, dateLength.ffiValue, timeLength.ffiValue); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = (() => {for (let i of Error.values) { if(i[1] === diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)) return Error[i[0]]; } return null;})(); + throw new Error('Error: ' + cause.value, { cause }); + } + return new ZonedDateTimeFormatter(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + } - })(); - }); - } + } - format_iso_datetime_with_custom_time_zone(arg_datetime, arg_time_zone) { - return diplomatRuntime.withDiplomatWrite(wasm, (write) => { - return (() => { + static createWithLengthsAndIso8601TimeZoneFallback(provider, locale, dateLength, timeLength, zoneOptions) { + + let slice_cleanup_callbacks = []; + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XZonedDateTimeFormatter_format_iso_datetime_with_custom_time_zone(diplomat_receive_buffer, this.underlying, arg_datetime.underlying, arg_time_zone.underlying, write); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = {}; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = Error_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); + const result = wasm.ICU4XZonedDateTimeFormatter_create_with_lengths_and_iso_8601_time_zone_fallback(diplomat_receive_buffer, provider.ffiValue, locale.ffiValue, dateLength.ffiValue, timeLength.ffiValue, ...zoneOptions._intoFFI(slice_cleanup_callbacks, {})); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = (() => {for (let i of Error.values) { if(i[1] === diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)) return Error[i[0]]; } return null;})(); + throw new Error('Error: ' + cause.value, { cause }); + } + return new ZonedDateTimeFormatter(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), []); + } finally { + + for (let cleanup of slice_cleanup_callbacks) { + cleanup(); + } + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + } - })(); - }); - } -} + } + + formatDatetimeWithCustomTimeZone(datetime, timeZone) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + + const write = wasm.diplomat_buffer_write_create(0); + const result = wasm.ICU4XZonedDateTimeFormatter_format_datetime_with_custom_time_zone(diplomat_receive_buffer, this.ffiValue, datetime.ffiValue, timeZone.ffiValue, write); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = (() => {for (let i of Error.values) { if(i[1] === diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)) return Error[i[0]]; } return null;})(); + throw new Error('Error: ' + cause.value, { cause }); + } + return diplomatRuntime.readString8(wasm, wasm.diplomat_buffer_write_get_bytes(write), wasm.diplomat_buffer_write_len(write)); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + wasm.diplomat_buffer_write_destroy(write); + + } + } + + formatIsoDatetimeWithCustomTimeZone(datetime, timeZone) { + + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + + const write = wasm.diplomat_buffer_write_create(0); + const result = wasm.ICU4XZonedDateTimeFormatter_format_iso_datetime_with_custom_time_zone(diplomat_receive_buffer, this.ffiValue, datetime.ffiValue, timeZone.ffiValue, write); + + try { + + if (!diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4)) { + const cause = (() => {for (let i of Error.values) { if(i[1] === diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)) return Error[i[0]]; } return null;})(); + throw new Error('Error: ' + cause.value, { cause }); + } + return diplomatRuntime.readString8(wasm, wasm.diplomat_buffer_write_get_bytes(write), wasm.diplomat_buffer_write_len(write)); + } finally { + + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + + wasm.diplomat_buffer_write_destroy(write); + + } + } + + + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/diplomat-runtime.d.ts b/ffi/capi/bindings/js/diplomat-runtime.d.ts index 7c3af621829..aa063d1a060 100644 --- a/ffi/capi/bindings/js/diplomat-runtime.d.ts +++ b/ffi/capi/bindings/js/diplomat-runtime.d.ts @@ -1,21 +1,2 @@ -/** - * An error that occurred in Rust. - */ -export class FFIError extends Error { - error_value: E; -} - -export type u8 = number; -export type i8 = number; -export type u16 = number; -export type i16 = number; -export type u32 = number; -export type i32 = number; -export type u64 = bigint; -export type i64 = bigint; -export type usize = number; -export type isize = number; -export type f32 = number; -export type f64 = number; export type char = string; export type pointer = number; \ No newline at end of file diff --git a/ffi/capi/bindings/js/diplomat-runtime.mjs b/ffi/capi/bindings/js/diplomat-runtime.mjs index c8df36003c3..e8d966ef2b1 100644 --- a/ffi/capi/bindings/js/diplomat-runtime.mjs +++ b/ffi/capi/bindings/js/diplomat-runtime.mjs @@ -14,7 +14,7 @@ export function withDiplomatWrite(wasm, callback) { callback(write); const outStringPtr = wasm.diplomat_buffer_write_get_bytes(write); if (outStringPtr == null) { - throw FFIError("Out of memory"); + throw Error("Out of memory"); } const outStringLen = wasm.diplomat_buffer_write_len(write); return readString8(wasm, outStringPtr, outStringLen); @@ -23,13 +23,6 @@ export function withDiplomatWrite(wasm, callback) { } } -export class FFIError extends Error { - constructor(error_value) { - super("Error over FFI"); - this.error_value = error_value; // (2) - } -} - export function extractCodePoint(str, param) { const cp = str.codePointAt?.(0); if ((!cp && cp !== 0) || [...str]?.length != 1) { @@ -105,7 +98,7 @@ export class DiplomatBuf { } static slice = (wasm, list, rustType) => { - const elementSize = rustType == "u8" || rustType == "i8" || rustType == "bool" ? 1 : + const elementSize = rustType == "u8" || rustType == "i8" || rustType == "boolean" ? 1 : rustType == "u16" || rustType == "i16" ? 2 : rustType == "u64" || rustType == "i64" || rustType == "f64" ? 8 : 4; @@ -115,11 +108,11 @@ export class DiplomatBuf { // Create an array view of the buffer. This gives us the `set` method which correctly handles untyped values const destination = - rustType == "u8" || rustType == "bool" ? new Uint8Array(wasm.memory.buffer, ptr, byteLength) : + rustType == "u8" || rustType == "boolean" ? new Uint8Array(wasm.memory.buffer, ptr, byteLength) : rustType == "i8" ? new Int8Array(wasm.memory.buffer, ptr, byteLength) : rustType == "u16" ? new Uint16Array(wasm.memory.buffer, ptr, byteLength) : rustType == "i16" ? new Int16Array(wasm.memory.buffer, ptr, byteLength) : - rustType == "i32" || rustType == "isize" ? new Int32Array(wasm.memory.buffer, ptr, byteLength) : + rustType == "i32" ? new Int32Array(wasm.memory.buffer, ptr, byteLength) : rustType == "u64" ? new BigUint64Array(wasm.memory.buffer, ptr, byteLength) : rustType == "i64" ? new BigInt64Array(wasm.memory.buffer, ptr, byteLength) : rustType == "f32" ? new Float32Array(wasm.memory.buffer, ptr, byteLength) : @@ -160,7 +153,7 @@ export class DiplomatBuf { var arrayType; switch (bufferType) { case "u8": - case "bool": + case "boolean": arrayType = Uint8Array; break; case "i8": @@ -173,11 +166,9 @@ export class DiplomatBuf { arrayType = Int16Array; break; case "i32": - case "isize": arrayType = Int32Array; break; case "u32": - case "usize": arrayType = Uint32Array; break; case "i64": diff --git a/ffi/capi/bindings/js/index.d.ts b/ffi/capi/bindings/js/index.d.ts index fdc82549b69..7cb45f87382 100644 --- a/ffi/capi/bindings/js/index.d.ts +++ b/ffi/capi/bindings/js/index.d.ts @@ -1,138 +1,271 @@ -export { FFIError, i8, u8, i16, u16, i32, u32, i64, u64, f32, f64, char } from './diplomat-runtime'; -export { AnyCalendarKind } from './AnyCalendarKind'; -export { Bidi } from './Bidi'; -export { BidiDirection } from './BidiDirection'; -export { BidiInfo } from './BidiInfo'; -export { BidiParagraph } from './BidiParagraph'; -export { Calendar } from './Calendar'; -export { CalendarError } from './CalendarError'; -export { CanonicalCombiningClassMap } from './CanonicalCombiningClassMap'; -export { CanonicalComposition } from './CanonicalComposition'; -export { CanonicalDecomposition } from './CanonicalDecomposition'; -export { CaseMapCloser } from './CaseMapCloser'; -export { CaseMapper } from './CaseMapper'; -export { CodePointMapData16 } from './CodePointMapData16'; -export { CodePointMapData8 } from './CodePointMapData8'; -export { CodePointRangeIterator } from './CodePointRangeIterator'; -export { CodePointRangeIteratorResult } from './CodePointRangeIteratorResult'; -export { CodePointSetBuilder } from './CodePointSetBuilder'; -export { CodePointSetData } from './CodePointSetData'; -export { Collator } from './Collator'; -export { CollatorAlternateHandling } from './CollatorAlternateHandling'; -export { CollatorBackwardSecondLevel } from './CollatorBackwardSecondLevel'; -export { CollatorCaseFirst } from './CollatorCaseFirst'; -export { CollatorCaseLevel } from './CollatorCaseLevel'; -export { CollatorMaxVariable } from './CollatorMaxVariable'; -export { CollatorNumeric } from './CollatorNumeric'; -export { CollatorOptionsV1 } from './CollatorOptionsV1'; -export { CollatorResolvedOptionsV1 } from './CollatorResolvedOptionsV1'; -export { CollatorStrength } from './CollatorStrength'; -export { ComposingNormalizer } from './ComposingNormalizer'; -export { CustomTimeZone } from './CustomTimeZone'; -export { DataError } from './DataError'; -export { DataProvider } from './DataProvider'; -export { DataStruct } from './DataStruct'; -export { Date } from './Date'; -export { DateFormatter } from './DateFormatter'; -export { DateLength } from './DateLength'; -export { DateTime } from './DateTime'; -export { DateTimeFormatter } from './DateTimeFormatter'; -export { Decomposed } from './Decomposed'; -export { DecomposingNormalizer } from './DecomposingNormalizer'; -export { DisplayNamesFallback } from './DisplayNamesFallback'; -export { DisplayNamesOptionsV1 } from './DisplayNamesOptionsV1'; -export { DisplayNamesStyle } from './DisplayNamesStyle'; -export { Error } from './Error'; -export { FixedDecimal } from './FixedDecimal'; -export { FixedDecimalFormatter } from './FixedDecimalFormatter'; -export { FixedDecimalGroupingStrategy } from './FixedDecimalGroupingStrategy'; -export { FixedDecimalLimitError } from './FixedDecimalLimitError'; -export { FixedDecimalParseError } from './FixedDecimalParseError'; -export { FixedDecimalRoundingIncrement } from './FixedDecimalRoundingIncrement'; -export { FixedDecimalRoundingMode } from './FixedDecimalRoundingMode'; -export { FixedDecimalSign } from './FixedDecimalSign'; -export { FixedDecimalSignDisplay } from './FixedDecimalSignDisplay'; -export { GeneralCategoryNameToMaskMapper } from './GeneralCategoryNameToMaskMapper'; -export { GraphemeClusterBreakIteratorLatin1 } from './GraphemeClusterBreakIteratorLatin1'; -export { GraphemeClusterBreakIteratorUtf16 } from './GraphemeClusterBreakIteratorUtf16'; -export { GraphemeClusterBreakIteratorUtf8 } from './GraphemeClusterBreakIteratorUtf8'; -export { GraphemeClusterSegmenter } from './GraphemeClusterSegmenter'; -export { GregorianDateFormatter } from './GregorianDateFormatter'; -export { GregorianDateTimeFormatter } from './GregorianDateTimeFormatter'; -export { GregorianZonedDateTimeFormatter } from './GregorianZonedDateTimeFormatter'; -export { IsoDate } from './IsoDate'; -export { IsoDateTime } from './IsoDateTime'; -export { IsoTimeZoneFormat } from './IsoTimeZoneFormat'; -export { IsoTimeZoneMinuteDisplay } from './IsoTimeZoneMinuteDisplay'; -export { IsoTimeZoneOptions } from './IsoTimeZoneOptions'; -export { IsoTimeZoneSecondDisplay } from './IsoTimeZoneSecondDisplay'; -export { IsoWeekday } from './IsoWeekday'; -export { LanguageDisplay } from './LanguageDisplay'; -export { LeadingAdjustment } from './LeadingAdjustment'; -export { LineBreakIteratorLatin1 } from './LineBreakIteratorLatin1'; -export { LineBreakIteratorUtf16 } from './LineBreakIteratorUtf16'; -export { LineBreakIteratorUtf8 } from './LineBreakIteratorUtf8'; -export { LineBreakOptionsV1 } from './LineBreakOptionsV1'; -export { LineBreakStrictness } from './LineBreakStrictness'; -export { LineBreakWordOption } from './LineBreakWordOption'; -export { LineSegmenter } from './LineSegmenter'; -export { List } from './List'; -export { ListFormatter } from './ListFormatter'; -export { ListLength } from './ListLength'; -export { Locale } from './Locale'; -export { LocaleCanonicalizer } from './LocaleCanonicalizer'; -export { LocaleDirection } from './LocaleDirection'; -export { LocaleDirectionality } from './LocaleDirectionality'; -export { LocaleDisplayNamesFormatter } from './LocaleDisplayNamesFormatter'; -export { LocaleExpander } from './LocaleExpander'; -export { LocaleFallbackConfig } from './LocaleFallbackConfig'; -export { LocaleFallbackIterator } from './LocaleFallbackIterator'; -export { LocaleFallbackPriority } from './LocaleFallbackPriority'; -export { LocaleFallbackSupplement } from './LocaleFallbackSupplement'; -export { LocaleFallbacker } from './LocaleFallbacker'; -export { LocaleFallbackerWithConfig } from './LocaleFallbackerWithConfig'; -export { LocaleParseError } from './LocaleParseError'; -export { Logger } from './Logger'; -export { MeasureUnit } from './MeasureUnit'; -export { MeasureUnitParser } from './MeasureUnitParser'; -export { MetazoneCalculator } from './MetazoneCalculator'; -export { Ordering } from './Ordering'; -export { PluralCategories } from './PluralCategories'; -export { PluralCategory } from './PluralCategory'; -export { PluralOperands } from './PluralOperands'; -export { PluralRules } from './PluralRules'; -export { PropertyValueNameToEnumMapper } from './PropertyValueNameToEnumMapper'; -export { RegionDisplayNames } from './RegionDisplayNames'; -export { ReorderedIndexMap } from './ReorderedIndexMap'; -export { ScriptExtensionsSet } from './ScriptExtensionsSet'; -export { ScriptWithExtensions } from './ScriptWithExtensions'; -export { ScriptWithExtensionsBorrowed } from './ScriptWithExtensionsBorrowed'; -export { SegmenterWordType } from './SegmenterWordType'; -export { SentenceBreakIteratorLatin1 } from './SentenceBreakIteratorLatin1'; -export { SentenceBreakIteratorUtf16 } from './SentenceBreakIteratorUtf16'; -export { SentenceBreakIteratorUtf8 } from './SentenceBreakIteratorUtf8'; -export { SentenceSegmenter } from './SentenceSegmenter'; -export { Time } from './Time'; -export { TimeFormatter } from './TimeFormatter'; -export { TimeLength } from './TimeLength'; -export { TimeZoneFormatter } from './TimeZoneFormatter'; -export { TimeZoneIdMapper } from './TimeZoneIdMapper'; -export { TimeZoneIdMapperWithFastCanonicalization } from './TimeZoneIdMapperWithFastCanonicalization'; -export { TimeZoneInvalidIdError } from './TimeZoneInvalidIdError'; -export { TimeZoneInvalidOffsetError } from './TimeZoneInvalidOffsetError'; -export { TitlecaseMapper } from './TitlecaseMapper'; -export { TitlecaseOptionsV1 } from './TitlecaseOptionsV1'; -export { TrailingCase } from './TrailingCase'; -export { TransformResult } from './TransformResult'; -export { UnicodeSetData } from './UnicodeSetData'; -export { UnitsConverter } from './UnitsConverter'; -export { UnitsConverterFactory } from './UnitsConverterFactory'; -export { WeekCalculator } from './WeekCalculator'; -export { WeekOf } from './WeekOf'; -export { WeekRelativeUnit } from './WeekRelativeUnit'; -export { WeekendContainsDay } from './WeekendContainsDay'; -export { WordBreakIteratorLatin1 } from './WordBreakIteratorLatin1'; -export { WordBreakIteratorUtf16 } from './WordBreakIteratorUtf16'; -export { WordBreakIteratorUtf8 } from './WordBreakIteratorUtf8'; -export { WordSegmenter } from './WordSegmenter'; -export { ZonedDateTimeFormatter } from './ZonedDateTimeFormatter'; + +export { char } from './diplomat-runtime'; + + +export { TitlecaseOptions } from "./TitlecaseOptions" + +export { CollatorOptions } from "./CollatorOptions" + +export { DisplayNamesOptions } from "./DisplayNamesOptions" + +export { LocaleFallbackConfig } from "./LocaleFallbackConfig" + +export { LineBreakOptions } from "./LineBreakOptions" + +export { IsoTimeZoneOptions } from "./IsoTimeZoneOptions" + +export { WeekendContainsDay } from "./WeekendContainsDay" + +export { ResolvedCollatorOptions } from "./ResolvedCollatorOptions" + +export { Decomposed } from "./Decomposed" + +export { PluralCategories } from "./PluralCategories" + +export { CodePointRangeIteratorResult } from "./CodePointRangeIteratorResult" + +export { WeekOf } from "./WeekOf" + +export { Bidi } from "./Bidi" + +export { BidiInfo } from "./BidiInfo" + +export { BidiParagraph } from "./BidiParagraph" + +export { ReorderedIndexMap } from "./ReorderedIndexMap" + +export { Calendar } from "./Calendar" + +export { CaseMapCloser } from "./CaseMapCloser" + +export { CaseMapper } from "./CaseMapper" + +export { TitlecaseMapper } from "./TitlecaseMapper" + +export { Collator } from "./Collator" + +export { CodePointSetBuilder } from "./CodePointSetBuilder" + +export { Date } from "./Date" + +export { IsoDate } from "./IsoDate" + +export { DateTime } from "./DateTime" + +export { IsoDateTime } from "./IsoDateTime" + +export { DateFormatter } from "./DateFormatter" + +export { DateTimeFormatter } from "./DateTimeFormatter" + +export { GregorianDateFormatter } from "./GregorianDateFormatter" + +export { GregorianDateTimeFormatter } from "./GregorianDateTimeFormatter" + +export { TimeFormatter } from "./TimeFormatter" + +export { FixedDecimalFormatter } from "./FixedDecimalFormatter" + +export { LocaleDisplayNamesFormatter } from "./LocaleDisplayNamesFormatter" + +export { RegionDisplayNames } from "./RegionDisplayNames" + +export { LocaleFallbackIterator } from "./LocaleFallbackIterator" + +export { LocaleFallbacker } from "./LocaleFallbacker" + +export { LocaleFallbackerWithConfig } from "./LocaleFallbackerWithConfig" + +export { FixedDecimal } from "./FixedDecimal" + +export { ListFormatter } from "./ListFormatter" + +export { LocaleCanonicalizer } from "./LocaleCanonicalizer" + +export { LocaleExpander } from "./LocaleExpander" + +export { Locale } from "./Locale" + +export { LocaleDirectionality } from "./LocaleDirectionality" + +export { Logger } from "./Logger" + +export { MetazoneCalculator } from "./MetazoneCalculator" + +export { ComposingNormalizer } from "./ComposingNormalizer" + +export { DecomposingNormalizer } from "./DecomposingNormalizer" + +export { CanonicalCombiningClassMap } from "./CanonicalCombiningClassMap" + +export { CanonicalComposition } from "./CanonicalComposition" + +export { CanonicalDecomposition } from "./CanonicalDecomposition" + +export { PluralOperands } from "./PluralOperands" + +export { PluralRules } from "./PluralRules" + +export { CodePointRangeIterator } from "./CodePointRangeIterator" + +export { CodePointMapData16 } from "./CodePointMapData16" + +export { CodePointMapData8 } from "./CodePointMapData8" + +export { GeneralCategoryNameToMaskMapper } from "./GeneralCategoryNameToMaskMapper" + +export { PropertyValueNameToEnumMapper } from "./PropertyValueNameToEnumMapper" + +export { CodePointSetData } from "./CodePointSetData" + +export { UnicodeSetData } from "./UnicodeSetData" + +export { DataProvider } from "./DataProvider" + +export { ScriptExtensionsSet } from "./ScriptExtensionsSet" + +export { ScriptWithExtensions } from "./ScriptWithExtensions" + +export { ScriptWithExtensionsBorrowed } from "./ScriptWithExtensionsBorrowed" + +export { GraphemeClusterBreakIteratorLatin1 } from "./GraphemeClusterBreakIteratorLatin1" + +export { GraphemeClusterBreakIteratorUtf16 } from "./GraphemeClusterBreakIteratorUtf16" + +export { GraphemeClusterBreakIteratorUtf8 } from "./GraphemeClusterBreakIteratorUtf8" + +export { GraphemeClusterSegmenter } from "./GraphemeClusterSegmenter" + +export { LineBreakIteratorLatin1 } from "./LineBreakIteratorLatin1" + +export { LineBreakIteratorUtf16 } from "./LineBreakIteratorUtf16" + +export { LineBreakIteratorUtf8 } from "./LineBreakIteratorUtf8" + +export { LineSegmenter } from "./LineSegmenter" + +export { SentenceBreakIteratorLatin1 } from "./SentenceBreakIteratorLatin1" + +export { SentenceBreakIteratorUtf16 } from "./SentenceBreakIteratorUtf16" + +export { SentenceBreakIteratorUtf8 } from "./SentenceBreakIteratorUtf8" + +export { SentenceSegmenter } from "./SentenceSegmenter" + +export { WordBreakIteratorLatin1 } from "./WordBreakIteratorLatin1" + +export { WordBreakIteratorUtf16 } from "./WordBreakIteratorUtf16" + +export { WordBreakIteratorUtf8 } from "./WordBreakIteratorUtf8" + +export { WordSegmenter } from "./WordSegmenter" + +export { Time } from "./Time" + +export { CustomTimeZone } from "./CustomTimeZone" + +export { TimeZoneFormatter } from "./TimeZoneFormatter" + +export { TimeZoneIdMapper } from "./TimeZoneIdMapper" + +export { TimeZoneIdMapperWithFastCanonicalization } from "./TimeZoneIdMapperWithFastCanonicalization" + +export { MeasureUnit } from "./MeasureUnit" + +export { MeasureUnitParser } from "./MeasureUnitParser" + +export { UnitsConverter } from "./UnitsConverter" + +export { UnitsConverterFactory } from "./UnitsConverterFactory" + +export { WeekCalculator } from "./WeekCalculator" + +export { GregorianZonedDateTimeFormatter } from "./GregorianZonedDateTimeFormatter" + +export { ZonedDateTimeFormatter } from "./ZonedDateTimeFormatter" + +export { BidiDirection } from "./BidiDirection" + +export { AnyCalendarKind } from "./AnyCalendarKind" + +export { LeadingAdjustment } from "./LeadingAdjustment" + +export { TrailingCase } from "./TrailingCase" + +export { CollatorAlternateHandling } from "./CollatorAlternateHandling" + +export { CollatorBackwardSecondLevel } from "./CollatorBackwardSecondLevel" + +export { CollatorCaseFirst } from "./CollatorCaseFirst" + +export { CollatorCaseLevel } from "./CollatorCaseLevel" + +export { CollatorMaxVariable } from "./CollatorMaxVariable" + +export { CollatorNumeric } from "./CollatorNumeric" + +export { CollatorStrength } from "./CollatorStrength" + +export { IsoWeekday } from "./IsoWeekday" + +export { DateLength } from "./DateLength" + +export { TimeLength } from "./TimeLength" + +export { FixedDecimalGroupingStrategy } from "./FixedDecimalGroupingStrategy" + +export { DisplayNamesFallback } from "./DisplayNamesFallback" + +export { DisplayNamesStyle } from "./DisplayNamesStyle" + +export { LanguageDisplay } from "./LanguageDisplay" + +export { CalendarError } from "./CalendarError" + +export { DataError } from "./DataError" + +export { Error } from "./Error" + +export { FixedDecimalLimitError } from "./FixedDecimalLimitError" + +export { FixedDecimalParseError } from "./FixedDecimalParseError" + +export { LocaleParseError } from "./LocaleParseError" + +export { TimeZoneInvalidIdError } from "./TimeZoneInvalidIdError" + +export { TimeZoneInvalidOffsetError } from "./TimeZoneInvalidOffsetError" + +export { LocaleFallbackPriority } from "./LocaleFallbackPriority" + +export { LocaleFallbackSupplement } from "./LocaleFallbackSupplement" + +export { FixedDecimalRoundingIncrement } from "./FixedDecimalRoundingIncrement" + +export { FixedDecimalRoundingMode } from "./FixedDecimalRoundingMode" + +export { FixedDecimalSign } from "./FixedDecimalSign" + +export { FixedDecimalSignDisplay } from "./FixedDecimalSignDisplay" + +export { ListLength } from "./ListLength" + +export { TransformResult } from "./TransformResult" + +export { LocaleDirection } from "./LocaleDirection" + +export { PluralCategory } from "./PluralCategory" + +export { LineBreakStrictness } from "./LineBreakStrictness" + +export { LineBreakWordOption } from "./LineBreakWordOption" + +export { SegmenterWordType } from "./SegmenterWordType" + +export { IsoTimeZoneFormat } from "./IsoTimeZoneFormat" + +export { IsoTimeZoneMinuteDisplay } from "./IsoTimeZoneMinuteDisplay" + +export { IsoTimeZoneSecondDisplay } from "./IsoTimeZoneSecondDisplay" + +export { WeekRelativeUnit } from "./WeekRelativeUnit" diff --git a/ffi/capi/bindings/js/index.mjs b/ffi/capi/bindings/js/index.mjs index a82bd7ec725..bd78628c4ee 100644 --- a/ffi/capi/bindings/js/index.mjs +++ b/ffi/capi/bindings/js/index.mjs @@ -1,138 +1,269 @@ -export { FFIError } from './diplomat-runtime.mjs'; -export { AnyCalendarKind } from './AnyCalendarKind.mjs'; -export { Bidi } from './Bidi.mjs'; -export { BidiDirection } from './BidiDirection.mjs'; -export { BidiInfo } from './BidiInfo.mjs'; -export { BidiParagraph } from './BidiParagraph.mjs'; -export { Calendar } from './Calendar.mjs'; -export { CalendarError } from './CalendarError.mjs'; -export { CanonicalCombiningClassMap } from './CanonicalCombiningClassMap.mjs'; -export { CanonicalComposition } from './CanonicalComposition.mjs'; -export { CanonicalDecomposition } from './CanonicalDecomposition.mjs'; -export { CaseMapCloser } from './CaseMapCloser.mjs'; -export { CaseMapper } from './CaseMapper.mjs'; -export { CodePointMapData16 } from './CodePointMapData16.mjs'; -export { CodePointMapData8 } from './CodePointMapData8.mjs'; -export { CodePointRangeIterator } from './CodePointRangeIterator.mjs'; -export { CodePointRangeIteratorResult } from './CodePointRangeIteratorResult.mjs'; -export { CodePointSetBuilder } from './CodePointSetBuilder.mjs'; -export { CodePointSetData } from './CodePointSetData.mjs'; -export { Collator } from './Collator.mjs'; -export { CollatorAlternateHandling } from './CollatorAlternateHandling.mjs'; -export { CollatorBackwardSecondLevel } from './CollatorBackwardSecondLevel.mjs'; -export { CollatorCaseFirst } from './CollatorCaseFirst.mjs'; -export { CollatorCaseLevel } from './CollatorCaseLevel.mjs'; -export { CollatorMaxVariable } from './CollatorMaxVariable.mjs'; -export { CollatorNumeric } from './CollatorNumeric.mjs'; -export { CollatorOptionsV1 } from './CollatorOptionsV1.mjs'; -export { CollatorResolvedOptionsV1 } from './CollatorResolvedOptionsV1.mjs'; -export { CollatorStrength } from './CollatorStrength.mjs'; -export { ComposingNormalizer } from './ComposingNormalizer.mjs'; -export { CustomTimeZone } from './CustomTimeZone.mjs'; -export { DataError } from './DataError.mjs'; -export { DataProvider } from './DataProvider.mjs'; -export { DataStruct } from './DataStruct.mjs'; -export { Date } from './Date.mjs'; -export { DateFormatter } from './DateFormatter.mjs'; -export { DateLength } from './DateLength.mjs'; -export { DateTime } from './DateTime.mjs'; -export { DateTimeFormatter } from './DateTimeFormatter.mjs'; -export { Decomposed } from './Decomposed.mjs'; -export { DecomposingNormalizer } from './DecomposingNormalizer.mjs'; -export { DisplayNamesFallback } from './DisplayNamesFallback.mjs'; -export { DisplayNamesOptionsV1 } from './DisplayNamesOptionsV1.mjs'; -export { DisplayNamesStyle } from './DisplayNamesStyle.mjs'; -export { Error } from './Error.mjs'; -export { FixedDecimal } from './FixedDecimal.mjs'; -export { FixedDecimalFormatter } from './FixedDecimalFormatter.mjs'; -export { FixedDecimalGroupingStrategy } from './FixedDecimalGroupingStrategy.mjs'; -export { FixedDecimalLimitError } from './FixedDecimalLimitError.mjs'; -export { FixedDecimalParseError } from './FixedDecimalParseError.mjs'; -export { FixedDecimalRoundingIncrement } from './FixedDecimalRoundingIncrement.mjs'; -export { FixedDecimalRoundingMode } from './FixedDecimalRoundingMode.mjs'; -export { FixedDecimalSign } from './FixedDecimalSign.mjs'; -export { FixedDecimalSignDisplay } from './FixedDecimalSignDisplay.mjs'; -export { GeneralCategoryNameToMaskMapper } from './GeneralCategoryNameToMaskMapper.mjs'; -export { GraphemeClusterBreakIteratorLatin1 } from './GraphemeClusterBreakIteratorLatin1.mjs'; -export { GraphemeClusterBreakIteratorUtf16 } from './GraphemeClusterBreakIteratorUtf16.mjs'; -export { GraphemeClusterBreakIteratorUtf8 } from './GraphemeClusterBreakIteratorUtf8.mjs'; -export { GraphemeClusterSegmenter } from './GraphemeClusterSegmenter.mjs'; -export { GregorianDateFormatter } from './GregorianDateFormatter.mjs'; -export { GregorianDateTimeFormatter } from './GregorianDateTimeFormatter.mjs'; -export { GregorianZonedDateTimeFormatter } from './GregorianZonedDateTimeFormatter.mjs'; -export { IsoDate } from './IsoDate.mjs'; -export { IsoDateTime } from './IsoDateTime.mjs'; -export { IsoTimeZoneFormat } from './IsoTimeZoneFormat.mjs'; -export { IsoTimeZoneMinuteDisplay } from './IsoTimeZoneMinuteDisplay.mjs'; -export { IsoTimeZoneOptions } from './IsoTimeZoneOptions.mjs'; -export { IsoTimeZoneSecondDisplay } from './IsoTimeZoneSecondDisplay.mjs'; -export { IsoWeekday } from './IsoWeekday.mjs'; -export { LanguageDisplay } from './LanguageDisplay.mjs'; -export { LeadingAdjustment } from './LeadingAdjustment.mjs'; -export { LineBreakIteratorLatin1 } from './LineBreakIteratorLatin1.mjs'; -export { LineBreakIteratorUtf16 } from './LineBreakIteratorUtf16.mjs'; -export { LineBreakIteratorUtf8 } from './LineBreakIteratorUtf8.mjs'; -export { LineBreakOptionsV1 } from './LineBreakOptionsV1.mjs'; -export { LineBreakStrictness } from './LineBreakStrictness.mjs'; -export { LineBreakWordOption } from './LineBreakWordOption.mjs'; -export { LineSegmenter } from './LineSegmenter.mjs'; -export { List } from './List.mjs'; -export { ListFormatter } from './ListFormatter.mjs'; -export { ListLength } from './ListLength.mjs'; -export { Locale } from './Locale.mjs'; -export { LocaleCanonicalizer } from './LocaleCanonicalizer.mjs'; -export { LocaleDirection } from './LocaleDirection.mjs'; -export { LocaleDirectionality } from './LocaleDirectionality.mjs'; -export { LocaleDisplayNamesFormatter } from './LocaleDisplayNamesFormatter.mjs'; -export { LocaleExpander } from './LocaleExpander.mjs'; -export { LocaleFallbackConfig } from './LocaleFallbackConfig.mjs'; -export { LocaleFallbackIterator } from './LocaleFallbackIterator.mjs'; -export { LocaleFallbackPriority } from './LocaleFallbackPriority.mjs'; -export { LocaleFallbackSupplement } from './LocaleFallbackSupplement.mjs'; -export { LocaleFallbacker } from './LocaleFallbacker.mjs'; -export { LocaleFallbackerWithConfig } from './LocaleFallbackerWithConfig.mjs'; -export { LocaleParseError } from './LocaleParseError.mjs'; -export { Logger } from './Logger.mjs'; -export { MeasureUnit } from './MeasureUnit.mjs'; -export { MeasureUnitParser } from './MeasureUnitParser.mjs'; -export { MetazoneCalculator } from './MetazoneCalculator.mjs'; -export { Ordering } from './Ordering.mjs'; -export { PluralCategories } from './PluralCategories.mjs'; -export { PluralCategory } from './PluralCategory.mjs'; -export { PluralOperands } from './PluralOperands.mjs'; -export { PluralRules } from './PluralRules.mjs'; -export { PropertyValueNameToEnumMapper } from './PropertyValueNameToEnumMapper.mjs'; -export { RegionDisplayNames } from './RegionDisplayNames.mjs'; -export { ReorderedIndexMap } from './ReorderedIndexMap.mjs'; -export { ScriptExtensionsSet } from './ScriptExtensionsSet.mjs'; -export { ScriptWithExtensions } from './ScriptWithExtensions.mjs'; -export { ScriptWithExtensionsBorrowed } from './ScriptWithExtensionsBorrowed.mjs'; -export { SegmenterWordType } from './SegmenterWordType.mjs'; -export { SentenceBreakIteratorLatin1 } from './SentenceBreakIteratorLatin1.mjs'; -export { SentenceBreakIteratorUtf16 } from './SentenceBreakIteratorUtf16.mjs'; -export { SentenceBreakIteratorUtf8 } from './SentenceBreakIteratorUtf8.mjs'; -export { SentenceSegmenter } from './SentenceSegmenter.mjs'; -export { Time } from './Time.mjs'; -export { TimeFormatter } from './TimeFormatter.mjs'; -export { TimeLength } from './TimeLength.mjs'; -export { TimeZoneFormatter } from './TimeZoneFormatter.mjs'; -export { TimeZoneIdMapper } from './TimeZoneIdMapper.mjs'; -export { TimeZoneIdMapperWithFastCanonicalization } from './TimeZoneIdMapperWithFastCanonicalization.mjs'; -export { TimeZoneInvalidIdError } from './TimeZoneInvalidIdError.mjs'; -export { TimeZoneInvalidOffsetError } from './TimeZoneInvalidOffsetError.mjs'; -export { TitlecaseMapper } from './TitlecaseMapper.mjs'; -export { TitlecaseOptionsV1 } from './TitlecaseOptionsV1.mjs'; -export { TrailingCase } from './TrailingCase.mjs'; -export { TransformResult } from './TransformResult.mjs'; -export { UnicodeSetData } from './UnicodeSetData.mjs'; -export { UnitsConverter } from './UnitsConverter.mjs'; -export { UnitsConverterFactory } from './UnitsConverterFactory.mjs'; -export { WeekCalculator } from './WeekCalculator.mjs'; -export { WeekOf } from './WeekOf.mjs'; -export { WeekRelativeUnit } from './WeekRelativeUnit.mjs'; -export { WeekendContainsDay } from './WeekendContainsDay.mjs'; -export { WordBreakIteratorLatin1 } from './WordBreakIteratorLatin1.mjs'; -export { WordBreakIteratorUtf16 } from './WordBreakIteratorUtf16.mjs'; -export { WordBreakIteratorUtf8 } from './WordBreakIteratorUtf8.mjs'; -export { WordSegmenter } from './WordSegmenter.mjs'; -export { ZonedDateTimeFormatter } from './ZonedDateTimeFormatter.mjs'; + + +export { TitlecaseOptions } from "./TitlecaseOptions.mjs" + +export { CollatorOptions } from "./CollatorOptions.mjs" + +export { DisplayNamesOptions } from "./DisplayNamesOptions.mjs" + +export { LocaleFallbackConfig } from "./LocaleFallbackConfig.mjs" + +export { LineBreakOptions } from "./LineBreakOptions.mjs" + +export { IsoTimeZoneOptions } from "./IsoTimeZoneOptions.mjs" + +export { WeekendContainsDay } from "./WeekendContainsDay.mjs" + +export { ResolvedCollatorOptions } from "./ResolvedCollatorOptions.mjs" + +export { Decomposed } from "./Decomposed.mjs" + +export { PluralCategories } from "./PluralCategories.mjs" + +export { CodePointRangeIteratorResult } from "./CodePointRangeIteratorResult.mjs" + +export { WeekOf } from "./WeekOf.mjs" + +export { Bidi } from "./Bidi.mjs" + +export { BidiInfo } from "./BidiInfo.mjs" + +export { BidiParagraph } from "./BidiParagraph.mjs" + +export { ReorderedIndexMap } from "./ReorderedIndexMap.mjs" + +export { Calendar } from "./Calendar.mjs" + +export { CaseMapCloser } from "./CaseMapCloser.mjs" + +export { CaseMapper } from "./CaseMapper.mjs" + +export { TitlecaseMapper } from "./TitlecaseMapper.mjs" + +export { Collator } from "./Collator.mjs" + +export { CodePointSetBuilder } from "./CodePointSetBuilder.mjs" + +export { Date } from "./Date.mjs" + +export { IsoDate } from "./IsoDate.mjs" + +export { DateTime } from "./DateTime.mjs" + +export { IsoDateTime } from "./IsoDateTime.mjs" + +export { DateFormatter } from "./DateFormatter.mjs" + +export { DateTimeFormatter } from "./DateTimeFormatter.mjs" + +export { GregorianDateFormatter } from "./GregorianDateFormatter.mjs" + +export { GregorianDateTimeFormatter } from "./GregorianDateTimeFormatter.mjs" + +export { TimeFormatter } from "./TimeFormatter.mjs" + +export { FixedDecimalFormatter } from "./FixedDecimalFormatter.mjs" + +export { LocaleDisplayNamesFormatter } from "./LocaleDisplayNamesFormatter.mjs" + +export { RegionDisplayNames } from "./RegionDisplayNames.mjs" + +export { LocaleFallbackIterator } from "./LocaleFallbackIterator.mjs" + +export { LocaleFallbacker } from "./LocaleFallbacker.mjs" + +export { LocaleFallbackerWithConfig } from "./LocaleFallbackerWithConfig.mjs" + +export { FixedDecimal } from "./FixedDecimal.mjs" + +export { ListFormatter } from "./ListFormatter.mjs" + +export { LocaleCanonicalizer } from "./LocaleCanonicalizer.mjs" + +export { LocaleExpander } from "./LocaleExpander.mjs" + +export { Locale } from "./Locale.mjs" + +export { LocaleDirectionality } from "./LocaleDirectionality.mjs" + +export { Logger } from "./Logger.mjs" + +export { MetazoneCalculator } from "./MetazoneCalculator.mjs" + +export { ComposingNormalizer } from "./ComposingNormalizer.mjs" + +export { DecomposingNormalizer } from "./DecomposingNormalizer.mjs" + +export { CanonicalCombiningClassMap } from "./CanonicalCombiningClassMap.mjs" + +export { CanonicalComposition } from "./CanonicalComposition.mjs" + +export { CanonicalDecomposition } from "./CanonicalDecomposition.mjs" + +export { PluralOperands } from "./PluralOperands.mjs" + +export { PluralRules } from "./PluralRules.mjs" + +export { CodePointRangeIterator } from "./CodePointRangeIterator.mjs" + +export { CodePointMapData16 } from "./CodePointMapData16.mjs" + +export { CodePointMapData8 } from "./CodePointMapData8.mjs" + +export { GeneralCategoryNameToMaskMapper } from "./GeneralCategoryNameToMaskMapper.mjs" + +export { PropertyValueNameToEnumMapper } from "./PropertyValueNameToEnumMapper.mjs" + +export { CodePointSetData } from "./CodePointSetData.mjs" + +export { UnicodeSetData } from "./UnicodeSetData.mjs" + +export { DataProvider } from "./DataProvider.mjs" + +export { ScriptExtensionsSet } from "./ScriptExtensionsSet.mjs" + +export { ScriptWithExtensions } from "./ScriptWithExtensions.mjs" + +export { ScriptWithExtensionsBorrowed } from "./ScriptWithExtensionsBorrowed.mjs" + +export { GraphemeClusterBreakIteratorLatin1 } from "./GraphemeClusterBreakIteratorLatin1.mjs" + +export { GraphemeClusterBreakIteratorUtf16 } from "./GraphemeClusterBreakIteratorUtf16.mjs" + +export { GraphemeClusterBreakIteratorUtf8 } from "./GraphemeClusterBreakIteratorUtf8.mjs" + +export { GraphemeClusterSegmenter } from "./GraphemeClusterSegmenter.mjs" + +export { LineBreakIteratorLatin1 } from "./LineBreakIteratorLatin1.mjs" + +export { LineBreakIteratorUtf16 } from "./LineBreakIteratorUtf16.mjs" + +export { LineBreakIteratorUtf8 } from "./LineBreakIteratorUtf8.mjs" + +export { LineSegmenter } from "./LineSegmenter.mjs" + +export { SentenceBreakIteratorLatin1 } from "./SentenceBreakIteratorLatin1.mjs" + +export { SentenceBreakIteratorUtf16 } from "./SentenceBreakIteratorUtf16.mjs" + +export { SentenceBreakIteratorUtf8 } from "./SentenceBreakIteratorUtf8.mjs" + +export { SentenceSegmenter } from "./SentenceSegmenter.mjs" + +export { WordBreakIteratorLatin1 } from "./WordBreakIteratorLatin1.mjs" + +export { WordBreakIteratorUtf16 } from "./WordBreakIteratorUtf16.mjs" + +export { WordBreakIteratorUtf8 } from "./WordBreakIteratorUtf8.mjs" + +export { WordSegmenter } from "./WordSegmenter.mjs" + +export { Time } from "./Time.mjs" + +export { CustomTimeZone } from "./CustomTimeZone.mjs" + +export { TimeZoneFormatter } from "./TimeZoneFormatter.mjs" + +export { TimeZoneIdMapper } from "./TimeZoneIdMapper.mjs" + +export { TimeZoneIdMapperWithFastCanonicalization } from "./TimeZoneIdMapperWithFastCanonicalization.mjs" + +export { MeasureUnit } from "./MeasureUnit.mjs" + +export { MeasureUnitParser } from "./MeasureUnitParser.mjs" + +export { UnitsConverter } from "./UnitsConverter.mjs" + +export { UnitsConverterFactory } from "./UnitsConverterFactory.mjs" + +export { WeekCalculator } from "./WeekCalculator.mjs" + +export { GregorianZonedDateTimeFormatter } from "./GregorianZonedDateTimeFormatter.mjs" + +export { ZonedDateTimeFormatter } from "./ZonedDateTimeFormatter.mjs" + +export { BidiDirection } from "./BidiDirection.mjs" + +export { AnyCalendarKind } from "./AnyCalendarKind.mjs" + +export { LeadingAdjustment } from "./LeadingAdjustment.mjs" + +export { TrailingCase } from "./TrailingCase.mjs" + +export { CollatorAlternateHandling } from "./CollatorAlternateHandling.mjs" + +export { CollatorBackwardSecondLevel } from "./CollatorBackwardSecondLevel.mjs" + +export { CollatorCaseFirst } from "./CollatorCaseFirst.mjs" + +export { CollatorCaseLevel } from "./CollatorCaseLevel.mjs" + +export { CollatorMaxVariable } from "./CollatorMaxVariable.mjs" + +export { CollatorNumeric } from "./CollatorNumeric.mjs" + +export { CollatorStrength } from "./CollatorStrength.mjs" + +export { IsoWeekday } from "./IsoWeekday.mjs" + +export { DateLength } from "./DateLength.mjs" + +export { TimeLength } from "./TimeLength.mjs" + +export { FixedDecimalGroupingStrategy } from "./FixedDecimalGroupingStrategy.mjs" + +export { DisplayNamesFallback } from "./DisplayNamesFallback.mjs" + +export { DisplayNamesStyle } from "./DisplayNamesStyle.mjs" + +export { LanguageDisplay } from "./LanguageDisplay.mjs" + +export { CalendarError } from "./CalendarError.mjs" + +export { DataError } from "./DataError.mjs" + +export { Error } from "./Error.mjs" + +export { FixedDecimalLimitError } from "./FixedDecimalLimitError.mjs" + +export { FixedDecimalParseError } from "./FixedDecimalParseError.mjs" + +export { LocaleParseError } from "./LocaleParseError.mjs" + +export { TimeZoneInvalidIdError } from "./TimeZoneInvalidIdError.mjs" + +export { TimeZoneInvalidOffsetError } from "./TimeZoneInvalidOffsetError.mjs" + +export { LocaleFallbackPriority } from "./LocaleFallbackPriority.mjs" + +export { LocaleFallbackSupplement } from "./LocaleFallbackSupplement.mjs" + +export { FixedDecimalRoundingIncrement } from "./FixedDecimalRoundingIncrement.mjs" + +export { FixedDecimalRoundingMode } from "./FixedDecimalRoundingMode.mjs" + +export { FixedDecimalSign } from "./FixedDecimalSign.mjs" + +export { FixedDecimalSignDisplay } from "./FixedDecimalSignDisplay.mjs" + +export { ListLength } from "./ListLength.mjs" + +export { TransformResult } from "./TransformResult.mjs" + +export { LocaleDirection } from "./LocaleDirection.mjs" + +export { PluralCategory } from "./PluralCategory.mjs" + +export { LineBreakStrictness } from "./LineBreakStrictness.mjs" + +export { LineBreakWordOption } from "./LineBreakWordOption.mjs" + +export { SegmenterWordType } from "./SegmenterWordType.mjs" + +export { IsoTimeZoneFormat } from "./IsoTimeZoneFormat.mjs" + +export { IsoTimeZoneMinuteDisplay } from "./IsoTimeZoneMinuteDisplay.mjs" + +export { IsoTimeZoneSecondDisplay } from "./IsoTimeZoneSecondDisplay.mjs" + +export { WeekRelativeUnit } from "./WeekRelativeUnit.mjs" diff --git a/ffi/capi/src/bidi.rs b/ffi/capi/src/bidi.rs index 4c048a7e185..058d41ecf04 100644 --- a/ffi/capi/src/bidi.rs +++ b/ffi/capi/src/bidi.rs @@ -47,7 +47,7 @@ pub mod ffi { FnInStruct, hidden )] - #[diplomat::attr(dart, disable)] + #[diplomat::attr(any(dart, js), disable)] pub fn for_text<'text>( &self, text: &'text DiplomatStr, @@ -76,9 +76,8 @@ pub mod ffi { FnInStruct, hidden )] - #[diplomat::attr(not(dart), disable)] - #[diplomat::attr(*, rename = "for_text")] - #[diplomat::skip_if_ast] + #[diplomat::attr(not(any(dart, js)), disable)] + #[diplomat::attr(any(dart, js), rename = "for_text")] pub fn for_text_valid_utf8<'text>( &self, text: &'text str, diff --git a/ffi/capi/src/casemap.rs b/ffi/capi/src/casemap.rs index 9d495f90001..a6235661729 100644 --- a/ffi/capi/src/casemap.rs +++ b/ffi/capi/src/casemap.rs @@ -29,7 +29,7 @@ pub mod ffi { } #[diplomat::rust_link(icu::casemap::titlecase::TitlecaseOptions, Struct)] - #[diplomat::attr(dart, rename = "TitlecaseOptions")] + #[diplomat::attr(any(dart, js), rename = "TitlecaseOptions")] pub struct TitlecaseOptionsV1 { pub leading_adjustment: LeadingAdjustment, pub trailing_case: TrailingCase, @@ -92,7 +92,7 @@ pub mod ffi { FnInStruct, hidden )] - #[diplomat::attr(dart, rename = "titlecaseSegmentWithOnlyCaseData")] + #[diplomat::attr(any(dart, js), rename = "titlecaseSegmentWithOnlyCaseData")] pub fn titlecase_segment_with_only_case_data_v1( &self, s: &str, @@ -279,7 +279,7 @@ pub mod ffi { FnInStruct, hidden )] - #[diplomat::attr(dart, rename = "titlecaseSegment")] + #[diplomat::attr(any(dart, js), rename = "titlecaseSegment")] pub fn titlecase_segment_v1( &self, s: &str, diff --git a/ffi/capi/src/collator.rs b/ffi/capi/src/collator.rs index 5f27069056e..5d0014cdfdf 100644 --- a/ffi/capi/src/collator.rs +++ b/ffi/capi/src/collator.rs @@ -7,10 +7,7 @@ pub mod ffi { use alloc::boxed::Box; - use crate::{ - common::ffi::Ordering, errors::ffi::DataError, locale_core::ffi::Locale, - provider::ffi::DataProvider, - }; + use crate::{errors::ffi::DataError, locale_core::ffi::Locale, provider::ffi::DataProvider}; #[diplomat::opaque] #[diplomat::rust_link(icu::collator::Collator, Struct)] @@ -18,7 +15,7 @@ pub mod ffi { #[diplomat::rust_link(icu::collator::CollatorOptions, Struct)] #[diplomat::rust_link(icu::collator::CollatorOptions::new, FnInStruct, hidden)] - #[diplomat::attr(dart, rename = "CollatorOptions")] + #[diplomat::attr(any(dart, js), rename = "CollatorOptions")] pub struct CollatorOptionsV1 { pub strength: CollatorStrength, pub alternate_handling: CollatorAlternateHandling, @@ -34,7 +31,7 @@ pub mod ffi { // `ResolvedCollatorOptions` makes more sense as English. #[diplomat::rust_link(icu::collator::ResolvedCollatorOptions, Struct)] #[diplomat::out] - #[diplomat::attr(dart, rename = "ResolvedCollatorOptions")] + #[diplomat::attr(any(dart, js), rename = "ResolvedCollatorOptions")] pub struct CollatorResolvedOptionsV1 { pub strength: CollatorStrength, pub alternate_handling: CollatorAlternateHandling, @@ -111,6 +108,7 @@ pub mod ffi { /// Construct a new Collator instance. #[diplomat::rust_link(icu::collator::Collator::try_new, FnInStruct)] #[diplomat::attr(all(supports = constructors, supports = fallible_constructors), constructor)] + #[diplomat::attr(js, rename = "create")] pub fn create_v1( provider: &DataProvider, locale: &Locale, @@ -129,42 +127,14 @@ pub mod ffi { )?))) } - /// Compare two strings. - /// - /// Ill-formed input is treated as if errors had been replaced with REPLACEMENT CHARACTERs according - /// to the WHATWG Encoding Standard. - #[diplomat::rust_link(icu::collator::Collator::compare_utf8, FnInStruct)] - #[diplomat::attr(*, disable)] - pub fn compare(&self, left: &DiplomatStr, right: &DiplomatStr) -> Ordering { - self.0.compare_utf8(left, right).into() - } - - /// Compare two strings. - #[diplomat::rust_link(icu::collator::Collator::compare, FnInStruct)] - #[diplomat::attr(*, disable)] - pub fn compare_valid_utf8(&self, left: &str, right: &str) -> Ordering { - self.0.compare(left, right).into() - } - /// Compare two strings. /// /// Ill-formed input is treated as if errors had been replaced with REPLACEMENT CHARACTERs according /// to the WHATWG Encoding Standard. #[diplomat::rust_link(icu::collator::Collator::compare_utf16, FnInStruct)] - #[diplomat::attr(*, disable)] - pub fn compare_utf16(&self, left: &DiplomatStr16, right: &DiplomatStr16) -> Ordering { - self.0.compare_utf16(left, right).into() - } - - /// Compare two strings. - /// - /// Ill-formed input is treated as if errors had been replaced with REPLACEMENT CHARACTERs according - /// to the WHATWG Encoding Standard. - #[diplomat::rust_link(icu::collator::Collator::compare_utf16, FnInStruct)] - #[diplomat::skip_if_ast] - #[diplomat::attr(dart, rename = "compare")] + #[diplomat::attr(any(dart, js), rename = "compare")] #[diplomat::attr(cpp, rename = "compare16")] - pub fn compare_utf16_( + pub fn compare_utf16( &self, left: &DiplomatStr16, right: &DiplomatStr16, @@ -176,11 +146,10 @@ pub mod ffi { /// /// Ill-formed input is treated as if errors had been replaced with REPLACEMENT CHARACTERs according /// to the WHATWG Encoding Standard. - #[diplomat::rust_link(icu::collator::Collator::compare_utf16, FnInStruct)] - #[diplomat::skip_if_ast] - #[diplomat::attr(dart, disable)] - #[diplomat::attr(cpp, rename = "compare")] - pub fn compare_(&self, left: &DiplomatStr, right: &DiplomatStr) -> core::cmp::Ordering { + #[diplomat::rust_link(icu::collator::Collator::compare_utf8, FnInStruct)] + #[diplomat::rust_link(icu::collator::Collator::compare, FnInStruct, hidden)] + #[diplomat::attr(any(dart, js), disable)] + pub fn compare(&self, left: &DiplomatStr, right: &DiplomatStr) -> core::cmp::Ordering { self.0.compare_utf8(left, right) } diff --git a/ffi/capi/src/common.rs b/ffi/capi/src/common.rs deleted file mode 100644 index 2fe99cdb106..00000000000 --- a/ffi/capi/src/common.rs +++ /dev/null @@ -1,18 +0,0 @@ -// This file is part of ICU4X. For terms of use, please see the file -// called LICENSE at the top level of the ICU4X source tree -// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). - -#[diplomat::bridge] -#[diplomat::abi_rename = "ICU4X{0}"] -pub mod ffi { - use alloc::boxed::Box; - - #[diplomat::enum_convert(core::cmp::Ordering)] - #[diplomat::rust_link(core::cmp::Ordering, Enum)] - #[diplomat::attr(*, disable)] - pub enum Ordering { - Less = -1, - Equal = 0, - Greater = 1, - } -} diff --git a/ffi/capi/src/data_struct.rs b/ffi/capi/src/data_struct.rs index 3aab8d780e9..8164db22a15 100644 --- a/ffi/capi/src/data_struct.rs +++ b/ffi/capi/src/data_struct.rs @@ -17,7 +17,7 @@ pub mod ffi { /// A generic data struct to be used by ICU4X /// /// This can be used to construct a StructDataProvider. - #[diplomat::attr(dart, disable)] + #[diplomat::attr(any(dart, js), disable)] pub struct DataStruct(pub(crate) AnyPayload); impl DataStruct { diff --git a/ffi/capi/src/decimal.rs b/ffi/capi/src/decimal.rs index b0ba1617efd..136d594507c 100644 --- a/ffi/capi/src/decimal.rs +++ b/ffi/capi/src/decimal.rs @@ -66,7 +66,7 @@ pub mod ffi { /// /// The contents of the data struct will be consumed: if you wish to use the struct again it will have to be reconstructed. /// Passing a consumed struct to this method will return an error. - #[diplomat::attr(dart, disable)] + #[diplomat::attr(any(dart, js), disable)] pub fn create_with_decimal_symbols_v1( data_struct: &DataStruct, grouping_strategy: FixedDecimalGroupingStrategy, diff --git a/ffi/capi/src/displaynames.rs b/ffi/capi/src/displaynames.rs index 61454a7f6ae..6a4f29ff904 100644 --- a/ffi/capi/src/displaynames.rs +++ b/ffi/capi/src/displaynames.rs @@ -24,7 +24,7 @@ pub mod ffi { pub struct RegionDisplayNames(pub icu_experimental::displaynames::RegionDisplayNames); #[diplomat::rust_link(icu::displaynames::options::DisplayNamesOptions, Struct)] - #[diplomat::attr(dart, rename = "DisplayNamesOptions")] + #[diplomat::attr(any(dart, js), rename = "DisplayNamesOptions")] pub struct DisplayNamesOptionsV1 { /// The optional formatting style to use for display name. pub style: DisplayNamesStyle, diff --git a/ffi/capi/src/fallbacker.rs b/ffi/capi/src/fallbacker.rs index 19c9a2c102c..526ec867b9a 100644 --- a/ffi/capi/src/fallbacker.rs +++ b/ffi/capi/src/fallbacker.rs @@ -137,36 +137,30 @@ pub mod ffi { } impl<'a> LocaleFallbackIterator<'a> { - /// Gets a snapshot of the current state of the locale. - #[diplomat::rust_link(icu::locale::fallback::LocaleFallbackIterator::get, FnInStruct)] + #[diplomat::attr(supports = iterators, iterator)] + #[diplomat::rust_link( + icu::locale::fallback::LocaleFallbackIterator::get, + FnInStruct, + hidden + )] + #[diplomat::rust_link( + icu::locale::fallback::LocaleFallbackIterator::step, + FnInStruct, + hidden + )] #[diplomat::rust_link( icu::locale::fallback::LocaleFallbackIterator::take, FnInStruct, hidden )] - #[diplomat::attr(*, disable)] - pub fn get(&self) -> Box { - Box::new(Locale(self.0.get().clone().into_locale())) - } - - /// Performs one step of the fallback algorithm, mutating the locale. - #[diplomat::rust_link(icu::locale::fallback::LocaleFallbackIterator::step, FnInStruct)] - #[diplomat::attr(*, disable)] - pub fn step(&mut self) { - self.0.step(); - } - - /// A combination of `get` and `step`. Returns the value that `get` would return - /// and advances the iterator until hitting `und`. - #[diplomat::attr(supports = iterators, iterator)] - #[diplomat::skip_if_ast] pub fn next(&mut self) -> Option> { - let current = self.get(); - if current.0 == icu_locale_core::Locale::UND { + let current = self.0.get(); + if current.is_und() { None } else { - self.step(); - Some(current) + let current = current.clone().into_locale(); + self.0.step(); + Some(Box::new(Locale(current))) } } } diff --git a/ffi/capi/src/fixed_decimal.rs b/ffi/capi/src/fixed_decimal.rs index 06c9efe0394..1a83625d589 100644 --- a/ffi/capi/src/fixed_decimal.rs +++ b/ffi/capi/src/fixed_decimal.rs @@ -66,7 +66,8 @@ pub mod ffi { impl FixedDecimal { /// Construct an [`FixedDecimal`] from an integer. #[diplomat::rust_link(fixed_decimal::FixedDecimal, Struct)] - #[diplomat::attr(dart, disable)] + #[diplomat::attr(any(dart), disable)] + #[diplomat::attr(js, rename = "fromInteger")] #[diplomat::attr(all(supports = constructors, supports = fallible_constructors, supports = named_constructors), named_constructor = "from_i32")] pub fn create_from_i32(v: i32) -> Box { Box::new(FixedDecimal(fixed_decimal::FixedDecimal::from(v))) @@ -74,7 +75,7 @@ pub mod ffi { /// Construct an [`FixedDecimal`] from an integer. #[diplomat::rust_link(fixed_decimal::FixedDecimal, Struct)] - #[diplomat::attr(dart, disable)] + #[diplomat::attr(any(dart, js), disable)] #[diplomat::attr(all(supports = constructors, supports = fallible_constructors, supports = named_constructors), named_constructor = "from_u32")] pub fn create_from_u32(v: u32) -> Box { Box::new(FixedDecimal(fixed_decimal::FixedDecimal::from(v))) @@ -82,7 +83,8 @@ pub mod ffi { /// Construct an [`FixedDecimal`] from an integer. #[diplomat::rust_link(fixed_decimal::FixedDecimal, Struct)] - #[diplomat::attr(dart, rename = "from_int")] + #[diplomat::attr(dart, rename = "fromInt")] + #[diplomat::attr(js, rename = "fromBigInt")] #[diplomat::attr(all(supports = constructors, supports = fallible_constructors, supports = named_constructors), named_constructor = "from_i64")] pub fn create_from_i64(v: i64) -> Box { Box::new(FixedDecimal(fixed_decimal::FixedDecimal::from(v))) @@ -90,7 +92,7 @@ pub mod ffi { /// Construct an [`FixedDecimal`] from an integer. #[diplomat::rust_link(fixed_decimal::FixedDecimal, Struct)] - #[diplomat::attr(dart, disable)] + #[diplomat::attr(any(dart, js), disable)] #[diplomat::attr(all(supports = constructors, supports = fallible_constructors, supports = named_constructors), named_constructor = "from_u64")] pub fn create_from_u64(v: u64) -> Box { Box::new(FixedDecimal(fixed_decimal::FixedDecimal::from(v))) @@ -100,8 +102,7 @@ pub mod ffi { #[diplomat::rust_link(fixed_decimal::FixedDecimal::try_from_f64, FnInStruct)] #[diplomat::rust_link(fixed_decimal::FloatPrecision, Enum)] #[diplomat::rust_link(fixed_decimal::DoublePrecision, Enum, hidden)] - #[diplomat::attr(dart, disable)] - #[diplomat::attr(dart, rename = "from_double_with_integer_precision")] + #[diplomat::attr(any(dart, js), disable)] #[diplomat::attr(all(supports = constructors, supports = fallible_constructors, supports = named_constructors), named_constructor = "from_f64_with_integer_precision")] pub fn create_from_f64_with_integer_precision( f: f64, @@ -117,6 +118,7 @@ pub mod ffi { #[diplomat::rust_link(fixed_decimal::FloatPrecision, Enum)] #[diplomat::rust_link(fixed_decimal::DoublePrecision, Enum, hidden)] #[diplomat::attr(dart, rename = "from_double_with_lower_magnitude")] + #[diplomat::attr(js, rename = "from_number_with_lower_magnitude")] #[diplomat::attr(all(supports = constructors, supports = fallible_constructors, supports = named_constructors), named_constructor = "from_f64_with_lower_magnitude")] pub fn create_from_f64_with_lower_magnitude( f: f64, @@ -133,6 +135,7 @@ pub mod ffi { #[diplomat::rust_link(fixed_decimal::FloatPrecision, Enum)] #[diplomat::rust_link(fixed_decimal::DoublePrecision, Enum, hidden)] #[diplomat::attr(dart, rename = "from_double_with_significant_digits")] + #[diplomat::attr(js, rename = "from_number_with_significant_digits")] #[diplomat::attr(all(supports = constructors, supports = fallible_constructors, supports = named_constructors), named_constructor = "from_f64_with_significant_digits")] pub fn create_from_f64_with_significant_digits( f: f64, @@ -149,7 +152,8 @@ pub mod ffi { #[diplomat::rust_link(fixed_decimal::FixedDecimal::try_from_f64, FnInStruct)] #[diplomat::rust_link(fixed_decimal::FloatPrecision, Enum)] #[diplomat::rust_link(fixed_decimal::DoublePrecision, Enum, hidden)] - #[diplomat::attr(dart, rename = "from_double_with_double_precision")] + #[diplomat::attr(dart, rename = "from_double_with_floating_precision")] + #[diplomat::attr(js, rename = "from_number_with_floating_precision")] #[diplomat::attr(all(supports = constructors, supports = fallible_constructors, supports = named_constructors), named_constructor = "from_f64_with_floating_precision")] pub fn create_from_f64_with_floating_precision( f: f64, @@ -163,6 +167,7 @@ pub mod ffi { /// Construct an [`FixedDecimal`] from a string. #[diplomat::rust_link(fixed_decimal::FixedDecimal::from_str, FnInStruct)] #[diplomat::attr(all(supports = constructors, supports = fallible_constructors, supports = named_constructors), named_constructor = "from_string")] + #[diplomat::attr(js, rename = "from_string")] pub fn create_from_string( v: &DiplomatStr, ) -> Result, FixedDecimalParseError> { diff --git a/ffi/capi/src/lib.rs b/ffi/capi/src/lib.rs index af942aa45df..f6b998946e4 100644 --- a/ffi/capi/src/lib.rs +++ b/ffi/capi/src/lib.rs @@ -57,8 +57,6 @@ extern crate alloc; extern crate libc_alloc; // Common modules - -pub mod common; pub mod data_struct; pub mod errors; pub mod locale_core; diff --git a/ffi/capi/src/list.rs b/ffi/capi/src/list.rs index 4b5c97e4df6..15e9c666656 100644 --- a/ffi/capi/src/list.rs +++ b/ffi/capi/src/list.rs @@ -6,53 +6,11 @@ #[diplomat::abi_rename = "ICU4X{0}"] pub mod ffi { use alloc::boxed::Box; - use alloc::string::String; - use alloc::vec::Vec; use crate::{errors::ffi::DataError, locale_core::ffi::Locale, provider::ffi::DataProvider}; use writeable::Writeable; - /// A list of strings - #[diplomat::opaque] - #[diplomat::attr(*, disable)] - pub struct List(pub Vec); - - impl List { - /// Create a new list of strings - #[diplomat::attr(all(supports = constructors, supports = fallible_constructors), constructor)] - pub fn create() -> Box { - Box::new(List(Vec::new())) - } - - /// Create a new list of strings with preallocated space to hold - /// at least `capacity` elements - #[diplomat::attr(all(supports = constructors, supports = fallible_constructors, supports = named_constructors), named_constructor = "with_capacity")] - pub fn create_with_capacity(capacity: usize) -> Box { - Box::new(List(Vec::with_capacity(capacity))) - } - - /// Push a string to the list - /// - /// Ill-formed input is treated as if errors had been replaced with REPLACEMENT CHARACTERs according - /// to the WHATWG Encoding Standard. - pub fn push(&mut self, val: &DiplomatStr) { - self.0.push(String::from_utf8_lossy(val).into_owned()); - } - - /// The number of elements in this list - #[diplomat::attr(supports = accessors, getter = "length")] - pub fn len(&self) -> usize { - self.0.len() - } - - /// Whether this list is empty - #[diplomat::attr(supports = accessors, getter)] - pub fn is_empty(&self) -> bool { - self.0.is_empty() - } - } - #[diplomat::rust_link(icu::list::ListLength, Enum)] #[diplomat::enum_convert(icu_list::ListLength, needs_wildcard)] pub enum ListLength { @@ -123,16 +81,7 @@ pub mod ffi { #[diplomat::rust_link(icu::list::ListFormatter::format, FnInStruct)] #[diplomat::rust_link(icu::list::ListFormatter::format_to_string, FnInStruct, hidden)] #[diplomat::rust_link(icu::list::FormattedList, Struct, hidden)] - #[diplomat::attr(*, disable)] - pub fn format(&self, list: &List, write: &mut DiplomatWrite) { - let _infallible = self.0.format(list.0.iter()).write_to(write); - } - - #[diplomat::rust_link(icu::list::ListFormatter::format, FnInStruct)] - #[diplomat::rust_link(icu::list::ListFormatter::format_to_string, FnInStruct, hidden)] - #[diplomat::rust_link(icu::list::FormattedList, Struct, hidden)] - #[diplomat::attr(dart, disable)] - #[diplomat::skip_if_ast] + #[diplomat::attr(any(dart, js), disable)] pub fn format_valid_utf8(&self, list: &[&str], write: &mut DiplomatWrite) { let _infallible = self.0.format(list.iter()).write_to(write); } @@ -140,8 +89,7 @@ pub mod ffi { #[diplomat::rust_link(icu::list::ListFormatter::format, FnInStruct)] #[diplomat::rust_link(icu::list::ListFormatter::format_to_string, FnInStruct, hidden)] #[diplomat::rust_link(icu::list::FormattedList, Struct, hidden)] - #[diplomat::attr(dart, disable)] - #[diplomat::skip_if_ast] + #[diplomat::attr(any(dart, js), disable)] pub fn format_utf8(&self, list: &[&DiplomatStr], write: &mut DiplomatWrite) { let _infallible = self .0 @@ -157,8 +105,7 @@ pub mod ffi { #[diplomat::rust_link(icu::list::ListFormatter::format, FnInStruct)] #[diplomat::rust_link(icu::list::ListFormatter::format_to_string, FnInStruct, hidden)] #[diplomat::rust_link(icu::list::FormattedList, Struct, hidden)] - #[diplomat::attr(dart, rename = "format")] - #[diplomat::skip_if_ast] + #[diplomat::attr(any(dart, js), rename = "format")] pub fn format_utf16(&self, list: &[&DiplomatStr16], write: &mut DiplomatWrite) { let _infallible = self .0 diff --git a/ffi/capi/src/locale_core.rs b/ffi/capi/src/locale_core.rs index a0ee9204cbd..208c2a608c9 100644 --- a/ffi/capi/src/locale_core.rs +++ b/ffi/capi/src/locale_core.rs @@ -7,7 +7,6 @@ pub mod ffi { use alloc::boxed::Box; - use crate::common::ffi::Ordering; use crate::errors::ffi::LocaleParseError; use writeable::Writeable; @@ -162,28 +161,13 @@ pub mod ffi { } #[diplomat::rust_link(icu::locale::Locale::strict_cmp, FnInStruct)] - #[diplomat::attr(*, disable)] - pub fn strict_cmp(&self, other: &DiplomatStr) -> Ordering { - self.0.strict_cmp(other).into() - } - - #[diplomat::rust_link(icu::locale::Locale::strict_cmp, FnInStruct)] - #[diplomat::skip_if_ast] - #[diplomat::attr(dart, rename = "compareToString")] - pub fn strict_cmp_(&self, other: &DiplomatStr) -> core::cmp::Ordering { + pub fn compare_to_string(&self, other: &DiplomatStr) -> core::cmp::Ordering { self.0.strict_cmp(other) } #[diplomat::rust_link(icu::locale::Locale::total_cmp, FnInStruct)] - #[diplomat::attr(*, disable)] - pub fn total_cmp(&self, other: &Self) -> Ordering { - self.0.total_cmp(&other.0).into() - } - - #[diplomat::rust_link(icu::locale::Locale::total_cmp, FnInStruct)] - #[diplomat::skip_if_ast] #[diplomat::attr(supports = comparators, comparison)] - pub fn total_cmp_(&self, other: &Self) -> core::cmp::Ordering { + pub fn compare_to(&self, other: &Self) -> core::cmp::Ordering { self.0.total_cmp(&other.0) } } diff --git a/ffi/capi/src/normalizer_properties.rs b/ffi/capi/src/normalizer_properties.rs index 9d11dc88354..cfe9c502e4e 100644 --- a/ffi/capi/src/normalizer_properties.rs +++ b/ffi/capi/src/normalizer_properties.rs @@ -56,7 +56,7 @@ pub mod ffi { Struct, compact )] - #[diplomat::attr(dart, disable)] + #[diplomat::attr(any(dart, js), disable)] pub fn get32(&self, ch: u32) -> u8 { self.0.get32(ch).0 } diff --git a/ffi/capi/src/properties_maps.rs b/ffi/capi/src/properties_maps.rs index b9964882328..6e8946ec787 100644 --- a/ffi/capi/src/properties_maps.rs +++ b/ffi/capi/src/properties_maps.rs @@ -49,7 +49,7 @@ pub mod ffi { FnInStruct, hidden )] - #[diplomat::attr(dart, disable)] + #[diplomat::attr(any(dart, js), disable)] pub fn get32(&self, cp: u32) -> u8 { self.get(cp) } @@ -283,7 +283,7 @@ pub mod ffi { FnInStruct, hidden )] - #[diplomat::attr(dart, disable)] + #[diplomat::attr(any(dart, js), disable)] pub fn get32(&self, cp: u32) -> u16 { self.get(cp) } diff --git a/ffi/capi/src/properties_sets.rs b/ffi/capi/src/properties_sets.rs index bd9bffef61a..f2b5178ad9c 100644 --- a/ffi/capi/src/properties_sets.rs +++ b/ffi/capi/src/properties_sets.rs @@ -34,7 +34,7 @@ pub mod ffi { FnInStruct, hidden )] - #[diplomat::attr(dart, disable)] + #[diplomat::attr(any(dart, js), disable)] pub fn contains32(&self, cp: u32) -> bool { self.contains(cp) } diff --git a/ffi/capi/src/properties_unisets.rs b/ffi/capi/src/properties_unisets.rs index d91eacc9b92..e08a68b65a3 100644 --- a/ffi/capi/src/properties_unisets.rs +++ b/ffi/capi/src/properties_unisets.rs @@ -41,7 +41,7 @@ pub mod ffi { FnInStruct, hidden )] - #[diplomat::attr(dart, disable)] + #[diplomat::attr(any(dart, js), disable)] pub fn contains32(&self, cp: u32) -> bool { self.contains_char(cp) } diff --git a/ffi/capi/src/provider.rs b/ffi/capi/src/provider.rs index 20610374a14..86b9b067bb3 100644 --- a/ffi/capi/src/provider.rs +++ b/ffi/capi/src/provider.rs @@ -54,7 +54,7 @@ pub mod ffi { feature = "provider_fs", not(any(target_arch = "wasm32", target_os = "none")) ))] - #[diplomat::attr(dart, disable)] + #[diplomat::attr(any(dart, js), disable)] #[diplomat::attr(all(supports = constructors, supports = fallible_constructors, supports = named_constructors), named_constructor = "fs")] pub fn create_fs(path: &DiplomatStr) -> Result, DataError> { Ok(Box::new(convert_buffer_provider( diff --git a/ffi/capi/src/segmenter_grapheme.rs b/ffi/capi/src/segmenter_grapheme.rs index 53bda926933..d5a72fa5641 100644 --- a/ffi/capi/src/segmenter_grapheme.rs +++ b/ffi/capi/src/segmenter_grapheme.rs @@ -65,7 +65,7 @@ pub mod ffi { hidden )] #[diplomat::rust_link(icu::segmenter::GraphemeClusterSegmenter::segment_utf8, FnInStruct)] - #[diplomat::attr(dart, disable)] + #[diplomat::attr(any(dart, js), disable)] pub fn segment_utf8<'a>( &'a self, input: &'a DiplomatStr, @@ -78,7 +78,7 @@ pub mod ffi { /// Ill-formed input is treated as if errors had been replaced with REPLACEMENT CHARACTERs according /// to the WHATWG Encoding Standard. #[diplomat::rust_link(icu::segmenter::GraphemeClusterSegmenter::segment_utf16, FnInStruct)] - #[diplomat::attr(dart, rename = "segment")] + #[diplomat::attr(any(dart, js), rename = "segment")] pub fn segment_utf16<'a>( &'a self, input: &'a DiplomatStr16, @@ -90,7 +90,7 @@ pub mod ffi { /// Segments a Latin-1 string. #[diplomat::rust_link(icu::segmenter::GraphemeClusterSegmenter::segment_latin1, FnInStruct)] - #[diplomat::attr(dart, disable)] + #[diplomat::attr(any(dart, js), disable)] pub fn segment_latin1<'a>( &'a self, input: &'a [u8], diff --git a/ffi/capi/src/segmenter_line.rs b/ffi/capi/src/segmenter_line.rs index a07bf2d7801..e63eb3d08f2 100644 --- a/ffi/capi/src/segmenter_line.rs +++ b/ffi/capi/src/segmenter_line.rs @@ -31,7 +31,7 @@ pub mod ffi { } #[diplomat::rust_link(icu::segmenter::LineBreakOptions, Struct)] - #[diplomat::attr(dart, rename = "LineBreakOptions")] + #[diplomat::attr(any(dart, js), rename = "LineBreakOptions")] pub struct LineBreakOptionsV1 { pub strictness: LineBreakStrictness, pub word_option: LineBreakWordOption, @@ -103,7 +103,7 @@ pub mod ffi { /// Construct a [`LineSegmenter`] with custom options. It automatically loads the best /// available payload data for Burmese, Khmer, Lao, and Thai. #[diplomat::rust_link(icu::segmenter::LineSegmenter::new_auto_with_options, FnInStruct)] - #[diplomat::attr(dart, rename = "auto_with_options")] + #[diplomat::attr(any(dart, js), rename = "auto_with_options")] #[diplomat::attr(all(supports = constructors, supports = fallible_constructors, supports = named_constructors), named_constructor = "auto_with_options_v1")] pub fn create_auto_with_options_v1( provider: &DataProvider, @@ -121,7 +121,7 @@ pub mod ffi { /// Construct a [`LineSegmenter`] with custom options and LSTM payload data for /// Burmese, Khmer, Lao, and Thai. #[diplomat::rust_link(icu::segmenter::LineSegmenter::new_lstm_with_options, FnInStruct)] - #[diplomat::attr(dart, rename = "lstm_with_options")] + #[diplomat::attr(any(dart, js), rename = "lstm_with_options")] #[diplomat::attr(all(supports = constructors, supports = fallible_constructors, supports = named_constructors), named_constructor = "lstm_with_options_v1")] pub fn create_lstm_with_options_v1( provider: &DataProvider, @@ -142,7 +142,7 @@ pub mod ffi { icu::segmenter::LineSegmenter::new_dictionary_with_options, FnInStruct )] - #[diplomat::attr(dart, rename = "dictionary_with_options")] + #[diplomat::attr(any(dart, js), rename = "dictionary_with_options")] #[diplomat::attr(all(supports = constructors, supports = fallible_constructors, supports = named_constructors), named_constructor = "dictionary_with_options_v1")] pub fn create_dictionary_with_options_v1( provider: &DataProvider, @@ -163,7 +163,7 @@ pub mod ffi { /// to the WHATWG Encoding Standard. #[diplomat::rust_link(icu::segmenter::LineSegmenter::segment_utf8, FnInStruct)] #[diplomat::rust_link(icu::segmenter::LineSegmenter::segment_str, FnInStruct, hidden)] - #[diplomat::attr(dart, disable)] + #[diplomat::attr(any(dart, js), disable)] pub fn segment_utf8<'a>( &'a self, input: &'a DiplomatStr, @@ -176,7 +176,7 @@ pub mod ffi { /// Ill-formed input is treated as if errors had been replaced with REPLACEMENT CHARACTERs according /// to the WHATWG Encoding Standard. #[diplomat::rust_link(icu::segmenter::LineSegmenter::segment_utf16, FnInStruct)] - #[diplomat::attr(dart, rename = "segment")] + #[diplomat::attr(any(dart, js), rename = "segment")] pub fn segment_utf16<'a>( &'a self, input: &'a DiplomatStr16, @@ -186,7 +186,7 @@ pub mod ffi { /// Segments a Latin-1 string. #[diplomat::rust_link(icu::segmenter::LineSegmenter::segment_latin1, FnInStruct)] - #[diplomat::attr(dart, disable)] + #[diplomat::attr(any(dart, js), disable)] pub fn segment_latin1<'a>(&'a self, input: &'a [u8]) -> Box> { Box::new(LineBreakIteratorLatin1(self.0.segment_latin1(input))) } diff --git a/ffi/capi/src/segmenter_sentence.rs b/ffi/capi/src/segmenter_sentence.rs index 327ef42a6f0..2a5ee32792c 100644 --- a/ffi/capi/src/segmenter_sentence.rs +++ b/ffi/capi/src/segmenter_sentence.rs @@ -56,7 +56,7 @@ pub mod ffi { /// to the WHATWG Encoding Standard. #[diplomat::rust_link(icu::segmenter::SentenceSegmenter::segment_utf8, FnInStruct)] #[diplomat::rust_link(icu::segmenter::SentenceSegmenter::segment_str, FnInStruct, hidden)] - #[diplomat::attr(dart, disable)] + #[diplomat::attr(any(dart, js), disable)] pub fn segment_utf8<'a>( &'a self, input: &'a DiplomatStr, @@ -69,7 +69,7 @@ pub mod ffi { /// Ill-formed input is treated as if errors had been replaced with REPLACEMENT CHARACTERs according /// to the WHATWG Encoding Standard. #[diplomat::rust_link(icu::segmenter::SentenceSegmenter::segment_utf16, FnInStruct)] - #[diplomat::attr(dart, rename = "segment")] + #[diplomat::attr(any(dart, js), rename = "segment")] pub fn segment_utf16<'a>( &'a self, input: &'a DiplomatStr16, @@ -79,7 +79,7 @@ pub mod ffi { /// Segments a Latin-1 string. #[diplomat::rust_link(icu::segmenter::SentenceSegmenter::segment_latin1, FnInStruct)] - #[diplomat::attr(dart, disable)] + #[diplomat::attr(any(dart, js), disable)] pub fn segment_latin1<'a>( &'a self, input: &'a [u8], diff --git a/ffi/capi/src/segmenter_word.rs b/ffi/capi/src/segmenter_word.rs index 725f36ee92e..e854140b2b0 100644 --- a/ffi/capi/src/segmenter_word.rs +++ b/ffi/capi/src/segmenter_word.rs @@ -105,7 +105,7 @@ pub mod ffi { /// to the WHATWG Encoding Standard. #[diplomat::rust_link(icu::segmenter::WordSegmenter::segment_utf8, FnInStruct)] #[diplomat::rust_link(icu::segmenter::WordSegmenter::segment_str, FnInStruct, hidden)] - #[diplomat::attr(dart, disable)] + #[diplomat::attr(any(dart, js), disable)] pub fn segment_utf8<'a>( &'a self, input: &'a DiplomatStr, @@ -118,7 +118,7 @@ pub mod ffi { /// Ill-formed input is treated as if errors had been replaced with REPLACEMENT CHARACTERs according /// to the WHATWG Encoding Standard. #[diplomat::rust_link(icu::segmenter::WordSegmenter::segment_utf16, FnInStruct)] - #[diplomat::attr(dart, rename = "segment")] + #[diplomat::attr(any(dart, js), rename = "segment")] pub fn segment_utf16<'a>( &'a self, input: &'a DiplomatStr16, @@ -128,7 +128,7 @@ pub mod ffi { /// Segments a Latin-1 string. #[diplomat::rust_link(icu::segmenter::WordSegmenter::segment_latin1, FnInStruct)] - #[diplomat::attr(dart, disable)] + #[diplomat::attr(any(dart, js), disable)] pub fn segment_latin1<'a>(&'a self, input: &'a [u8]) -> Box> { Box::new(WordBreakIteratorLatin1(self.0.segment_latin1(input))) } diff --git a/ffi/capi/src/units_converter.rs b/ffi/capi/src/units_converter.rs index 4af9883070f..27d7c396cad 100644 --- a/ffi/capi/src/units_converter.rs +++ b/ffi/capi/src/units_converter.rs @@ -101,14 +101,15 @@ pub mod ffi { #[diplomat::rust_link(icu::experimental::units::converter::UnitsConverter, Struct)] pub struct UnitsConverter(pub icu_experimental::units::converter::UnitsConverter); impl UnitsConverter { - /// Converts the input value in float from the input unit to the output unit (that have been used to create this converter). + /// Converts the input value from the input unit to the output unit (that have been used to create this converter). /// NOTE: /// The conversion using floating-point operations is not as accurate as the conversion using ratios. #[diplomat::rust_link( icu::experimental::units::converter::UnitsConverter::convert, FnInStruct )] - #[diplomat::attr(dart, rename = "convert_double")] + #[diplomat::attr(any(dart, cpp, c), rename = "convert_double")] + #[diplomat::attr(js, rename = "convert")] pub fn convert_f64(&self, value: f64) -> f64 { self.0.convert(&value) } diff --git a/ffi/npm/Makefile b/ffi/npm/Makefile index 86608880a28..af77d6c8eff 100644 --- a/ffi/npm/Makefile +++ b/ffi/npm/Makefile @@ -11,7 +11,7 @@ PINNED_CI_NIGHTLY ?= "nightly-2023-08-08" # https://github.com/unicode-org/icu4x/issues/2753 WASM_STACK_SIZE := 100000 -lib/index.mjs: +lib/index.mjs: FORCE rm -rf lib cp -r ../capi/bindings/js lib diff --git a/ffi/npm/test/data-providers.mjs b/ffi/npm/test/data-providers.mjs index fd65e308a06..775087cbbb7 100644 --- a/ffi/npm/test/data-providers.mjs +++ b/ffi/npm/test/data-providers.mjs @@ -4,16 +4,16 @@ import test from 'ava'; -import { FixedDecimal, Locale, DataProvider, FixedDecimalFormatter } from "icu4x" +import { FixedDecimal, Locale, DataProvider, FixedDecimalFormatter, FixedDecimalGroupingStrategy } from 'icu4x'; -test("use create_compiled to format a simple decimal", async t => { - const locale = Locale.create_from_string("bn"); - const provider = DataProvider.create_compiled(); +test('use createCompiled to format a simple decimal', async t => { + const locale = Locale.createFromString('bn'); + const provider = DataProvider.createCompiled(); - const format = FixedDecimalFormatter.create_with_grouping_strategy(provider, locale, "Auto"); + const format = FixedDecimalFormatter.createWithGroupingStrategy(provider, locale, FixedDecimalGroupingStrategy.Auto); - const decimal = FixedDecimal.create_from_i32(1234); - decimal.multiply_pow10(-2); + const decimal = FixedDecimal.fromInteger(1234); + decimal.multiplyPow10(-2); - t.is(format.format(decimal), "১২.৩৪"); + t.is(format.format(decimal), '১২.৩৪'); }); diff --git a/ffi/npm/test/fixed-decimal-format.mjs b/ffi/npm/test/fixed-decimal-format.mjs index 8b468e96399..55823cea2b0 100644 --- a/ffi/npm/test/fixed-decimal-format.mjs +++ b/ffi/npm/test/fixed-decimal-format.mjs @@ -4,29 +4,29 @@ import test from 'ava'; -import { FixedDecimal, Locale, DataProvider, FixedDecimalFormatter } from "icu4x" +import { FixedDecimal, Locale, DataProvider, FixedDecimalFormatter, FixedDecimalSign, FixedDecimalGroupingStrategy } from 'icu4x'; -const locale = Locale.create_from_string("bn"); -const provider = DataProvider.create_compiled(); -const format = FixedDecimalFormatter.create_with_grouping_strategy(provider, locale, "Auto"); +const locale = Locale.createFromString('bn'); +const provider = DataProvider.createCompiled(); +const format = FixedDecimalFormatter.createWithGroupingStrategy(provider, locale, FixedDecimalGroupingStrategy.Auto); -test("format a simple decimal", t => { - const decimal = FixedDecimal.create_from_i32(1234); - decimal.multiply_pow10(-2); +test('format a simple decimal', t => { + const decimal = FixedDecimal.fromInteger(1234); + decimal.multiplyPow10(-2); - t.is(format.format(decimal), "১২.৩৪"); + t.is(format.format(decimal), '১২.৩৪'); }); -test("format a long decimal", t => { - const decimal = FixedDecimal.create_from_i32(1000007); +test('format a long decimal', t => { + const decimal = FixedDecimal.fromInteger(1000007); - t.is(format.format(decimal), "১০,০০,০০৭"); + t.is(format.format(decimal), '১০,০০,০০৭'); }); -test("format a negated, scaled decimal", t => { - const decimal = FixedDecimal.create_from_i32(1000007); - decimal.multiply_pow10(2); - decimal.set_sign("Negative"); +test('format a negated, scaled decimal', t => { + const decimal = FixedDecimal.fromInteger(1000007); + decimal.multiplyPow10(2); + decimal.sign = FixedDecimalSign.Negative; - t.is(format.format(decimal), "-১০,০০,০০,৭০০"); + t.is(format.format(decimal), '-১০,০০,০০,৭০০'); }); diff --git a/ffi/npm/test/fixed-decimal.mjs b/ffi/npm/test/fixed-decimal.mjs index 10b200bbf3c..a0352450192 100644 --- a/ffi/npm/test/fixed-decimal.mjs +++ b/ffi/npm/test/fixed-decimal.mjs @@ -4,24 +4,24 @@ import test from 'ava'; -import { FixedDecimal } from "icu4x" +import { FixedDecimal, FixedDecimalSign } from 'icu4x'; -test("convert a simple decimal to a string", t => { - const decimal = FixedDecimal.create_from_i64(1234n); +test('convert a simple decimal to a string', t => { + const decimal = FixedDecimal.fromBigInt(1234n); - t.is(decimal.to_string(), "1234"); + t.is(decimal.toString(), '1234'); }); -test("multiply a decimal by a power of 10", t => { - const decimal = FixedDecimal.create_from_i32(1234); - decimal.multiply_pow10(-2); +test('multiply a decimal by a power of 10', t => { + const decimal = FixedDecimal.fromInteger(1234); + decimal.multiplyPow10(-2); - t.is(decimal.to_string(), "12.34"); + t.is(decimal.toString(), '12.34'); }); -test("negate a decimal", t => { - const decimal = FixedDecimal.create_from_i32(1234); - decimal.set_sign("Negative"); +test('negate a decimal', t => { + const decimal = FixedDecimal.fromInteger(1234); + decimal.sign = FixedDecimalSign.Negative; - t.is(decimal.to_string(), "-1234"); + t.is(decimal.toString(), '-1234'); }); diff --git a/tools/diplomat-gen/src/main.rs b/tools/diplomat-gen/src/main.rs index 6a6e44b1f7a..d7245f66d45 100644 --- a/tools/diplomat-gen/src/main.rs +++ b/tools/diplomat-gen/src/main.rs @@ -16,6 +16,7 @@ fn main() -> std::io::Result<()> { match lang.as_str() { "cpp" => "cpp2", "c" => "c2", + "js" => "js2", l => l, }, &{ diff --git a/tutorials/c/Cargo.lock b/tutorials/c/Cargo.lock index 1d3236039fe..7adec97f5d6 100644 --- a/tutorials/c/Cargo.lock +++ b/tutorials/c/Cargo.lock @@ -47,7 +47,7 @@ dependencies = [ [[package]] name = "diplomat" version = "0.8.0" -source = "git+https://github.com/rust-diplomat/diplomat?rev=772da44c9ee66862eaafb23a40a197d7da499007#772da44c9ee66862eaafb23a40a197d7da499007" +source = "git+https://github.com/rust-diplomat/diplomat?rev=5265bfca157e9d94221ed52003e97e3b5ed9ffbe#5265bfca157e9d94221ed52003e97e3b5ed9ffbe" dependencies = [ "diplomat_core", "proc-macro2", @@ -58,7 +58,7 @@ dependencies = [ [[package]] name = "diplomat-runtime" version = "0.8.1" -source = "git+https://github.com/rust-diplomat/diplomat?rev=772da44c9ee66862eaafb23a40a197d7da499007#772da44c9ee66862eaafb23a40a197d7da499007" +source = "git+https://github.com/rust-diplomat/diplomat?rev=5265bfca157e9d94221ed52003e97e3b5ed9ffbe#5265bfca157e9d94221ed52003e97e3b5ed9ffbe" dependencies = [ "log", ] @@ -66,7 +66,7 @@ dependencies = [ [[package]] name = "diplomat_core" version = "0.8.0" -source = "git+https://github.com/rust-diplomat/diplomat?rev=772da44c9ee66862eaafb23a40a197d7da499007#772da44c9ee66862eaafb23a40a197d7da499007" +source = "git+https://github.com/rust-diplomat/diplomat?rev=5265bfca157e9d94221ed52003e97e3b5ed9ffbe#5265bfca157e9d94221ed52003e97e3b5ed9ffbe" dependencies = [ "lazy_static", "proc-macro2", diff --git a/tutorials/cpp/Cargo.lock b/tutorials/cpp/Cargo.lock index 63f1da869d6..97498a2bc11 100644 --- a/tutorials/cpp/Cargo.lock +++ b/tutorials/cpp/Cargo.lock @@ -60,7 +60,7 @@ dependencies = [ [[package]] name = "diplomat" version = "0.8.0" -source = "git+https://github.com/rust-diplomat/diplomat?rev=dbb32938c2d0176474f44907df057afd1df2dea7#dbb32938c2d0176474f44907df057afd1df2dea7" +source = "git+https://github.com/rust-diplomat/diplomat?rev=5265bfca157e9d94221ed52003e97e3b5ed9ffbe#5265bfca157e9d94221ed52003e97e3b5ed9ffbe" dependencies = [ "diplomat_core", "proc-macro2", @@ -70,8 +70,8 @@ dependencies = [ [[package]] name = "diplomat-runtime" -version = "0.8.0" -source = "git+https://github.com/rust-diplomat/diplomat?rev=dbb32938c2d0176474f44907df057afd1df2dea7#dbb32938c2d0176474f44907df057afd1df2dea7" +version = "0.8.1" +source = "git+https://github.com/rust-diplomat/diplomat?rev=5265bfca157e9d94221ed52003e97e3b5ed9ffbe#5265bfca157e9d94221ed52003e97e3b5ed9ffbe" dependencies = [ "log", ] @@ -79,7 +79,7 @@ dependencies = [ [[package]] name = "diplomat_core" version = "0.8.0" -source = "git+https://github.com/rust-diplomat/diplomat?rev=dbb32938c2d0176474f44907df057afd1df2dea7#dbb32938c2d0176474f44907df057afd1df2dea7" +source = "git+https://github.com/rust-diplomat/diplomat?rev=5265bfca157e9d94221ed52003e97e3b5ed9ffbe#5265bfca157e9d94221ed52003e97e3b5ed9ffbe" dependencies = [ "lazy_static", "proc-macro2", @@ -130,7 +130,6 @@ dependencies = [ "calendrical_calculations", "displaydoc", "icu_calendar_data", - "icu_locale", "icu_locale_core", "icu_provider", "serde", @@ -142,6 +141,10 @@ dependencies = [ [[package]] name = "icu_calendar_data" version = "1.5.0" +dependencies = [ + "icu_locale", + "icu_provider_baked", +] [[package]] name = "icu_capi" @@ -195,6 +198,9 @@ dependencies = [ [[package]] name = "icu_casemap_data" version = "1.5.0" +dependencies = [ + "icu_provider_baked", +] [[package]] name = "icu_collator" @@ -203,7 +209,6 @@ dependencies = [ "displaydoc", "icu_collator_data", "icu_collections", - "icu_locale", "icu_normalizer", "icu_properties", "icu_provider", @@ -217,6 +222,10 @@ dependencies = [ [[package]] name = "icu_collator_data" version = "1.5.0" +dependencies = [ + "icu_locale", + "icu_provider_baked", +] [[package]] name = "icu_collections" @@ -239,7 +248,6 @@ dependencies = [ "icu_calendar", "icu_datetime_data", "icu_decimal", - "icu_locale", "icu_locale_core", "icu_plurals", "icu_provider", @@ -255,6 +263,10 @@ dependencies = [ [[package]] name = "icu_datetime_data" version = "1.5.0" +dependencies = [ + "icu_locale", + "icu_provider_baked", +] [[package]] name = "icu_decimal" @@ -263,7 +275,6 @@ dependencies = [ "displaydoc", "fixed_decimal", "icu_decimal_data", - "icu_locale", "icu_provider", "serde", "writeable", @@ -272,6 +283,10 @@ dependencies = [ [[package]] name = "icu_decimal_data" version = "1.5.0" +dependencies = [ + "icu_locale", + "icu_provider_baked", +] [[package]] name = "icu_experimental" @@ -305,6 +320,10 @@ dependencies = [ [[package]] name = "icu_experimental_data" version = "0.1.0" +dependencies = [ + "icu_locale", + "icu_provider_baked", +] [[package]] name = "icu_list" @@ -313,7 +332,6 @@ dependencies = [ "deduplicating_array", "displaydoc", "icu_list_data", - "icu_locale", "icu_provider", "regex-automata", "serde", @@ -323,6 +341,10 @@ dependencies = [ [[package]] name = "icu_list_data" version = "1.5.0" +dependencies = [ + "icu_locale", + "icu_provider_baked", +] [[package]] name = "icu_locale" @@ -352,6 +374,9 @@ dependencies = [ [[package]] name = "icu_locale_data" version = "1.5.0" +dependencies = [ + "icu_provider_baked", +] [[package]] name = "icu_normalizer" @@ -373,6 +398,9 @@ dependencies = [ [[package]] name = "icu_normalizer_data" version = "1.5.0" +dependencies = [ + "icu_provider_baked", +] [[package]] name = "icu_pattern" @@ -392,7 +420,6 @@ version = "1.5.0" dependencies = [ "displaydoc", "fixed_decimal", - "icu_locale", "icu_plurals_data", "icu_provider", "serde", @@ -402,6 +429,10 @@ dependencies = [ [[package]] name = "icu_plurals_data" version = "1.5.0" +dependencies = [ + "icu_locale", + "icu_provider_baked", +] [[package]] name = "icu_properties" @@ -409,7 +440,6 @@ version = "1.5.0" dependencies = [ "displaydoc", "icu_collections", - "icu_locale", "icu_properties_data", "icu_provider", "serde", @@ -421,6 +451,10 @@ dependencies = [ [[package]] name = "icu_properties_data" version = "1.5.0" +dependencies = [ + "icu_locale", + "icu_provider_baked", +] [[package]] name = "icu_provider" @@ -446,13 +480,21 @@ name = "icu_provider_adapters" version = "1.5.0" dependencies = [ "icu_locale", - "icu_locale_core", "icu_provider", "serde", "tinystr", "zerovec", ] +[[package]] +name = "icu_provider_baked" +version = "1.5.0" +dependencies = [ + "icu_provider", + "writeable", + "zerotrie", +] + [[package]] name = "icu_provider_blob" version = "1.5.0" @@ -502,6 +544,10 @@ dependencies = [ [[package]] name = "icu_segmenter_data" version = "1.5.0" +dependencies = [ + "icu_locale", + "icu_provider_baked", +] [[package]] name = "icu_timezone" @@ -520,6 +566,9 @@ dependencies = [ [[package]] name = "icu_timezone_data" version = "1.5.0" +dependencies = [ + "icu_provider_baked", +] [[package]] name = "itoa" @@ -558,12 +607,6 @@ version = "0.4.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" -[[package]] -name = "memchr" -version = "2.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" - [[package]] name = "num-bigint" version = "0.4.5" @@ -655,12 +698,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.2.0" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9368763f5a9b804326f3af749e16f9abf378d227bcdee7634b13d8f17793782" -dependencies = [ - "memchr", -] +checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" [[package]] name = "ryu" @@ -978,7 +1018,7 @@ dependencies = [ [[package]] name = "zerovec" -version = "0.10.2" +version = "0.10.4" dependencies = [ "serde", "yoke", @@ -988,7 +1028,7 @@ dependencies = [ [[package]] name = "zerovec-derive" -version = "0.10.2" +version = "0.10.3" dependencies = [ "proc-macro2", "quote", @@ -1015,6 +1055,10 @@ version = "0.1.8" name = "icu" version = "1.5.0" +[[patch.unused]] +name = "icu4x-datagen" +version = "1.5.0" + [[patch.unused]] name = "icu4x_ecma402" version = "0.8.2" @@ -1027,10 +1071,6 @@ version = "0.0.0" name = "icu_codepointtrie_builder" version = "0.3.8" -[[patch.unused]] -name = "icu_datagen" -version = "1.5.0" - [[patch.unused]] name = "icu_freertos" version = "1.5.0" @@ -1039,6 +1079,18 @@ version = "1.5.0" name = "icu_harfbuzz" version = "0.2.0" +[[patch.unused]] +name = "icu_provider_export" +version = "1.5.0" + +[[patch.unused]] +name = "icu_provider_registry" +version = "1.5.0" + +[[patch.unused]] +name = "icu_provider_source" +version = "1.5.0" + [[patch.unused]] name = "ixdtf" version = "0.2.0" diff --git a/tutorials/cpp/units_converter.cpp b/tutorials/cpp/units_converter.cpp index aaf25dac9cc..9cb8eda12db 100644 --- a/tutorials/cpp/units_converter.cpp +++ b/tutorials/cpp/units_converter.cpp @@ -17,10 +17,10 @@ int main() { auto from = parser->parse("meter"); auto to = parser->parse("foot"); auto converter = converter_factory->converter(*from.get(), *to.get()); - auto result = converter->convert_f64(1.0); + auto result = converter->convert_double(1.0); auto converter_cloned = converter->clone(); - auto result_cloned = converter_cloned->convert_f64(1.0); + auto result_cloned = converter_cloned->convert_double(1.0); if (std::abs(result - 3.28084) > 0.00001 && std::abs(result_cloned - 3.28084) > 0.00001) { diff --git a/tutorials/js-tiny/Cargo.lock b/tutorials/js-tiny/Cargo.lock index 16f0be6f5ba..f43d9aca06a 100644 --- a/tutorials/js-tiny/Cargo.lock +++ b/tutorials/js-tiny/Cargo.lock @@ -47,7 +47,7 @@ dependencies = [ [[package]] name = "diplomat" version = "0.8.0" -source = "git+https://github.com/rust-diplomat/diplomat?rev=bcf0fc679266bb5ee0c7b25a371398158e81a7e1#bcf0fc679266bb5ee0c7b25a371398158e81a7e1" +source = "git+https://github.com/rust-diplomat/diplomat?rev=e12d47299c9a447730d30e8b7d8fcee1839d7d87#e12d47299c9a447730d30e8b7d8fcee1839d7d87" dependencies = [ "diplomat_core", "proc-macro2", @@ -57,8 +57,8 @@ dependencies = [ [[package]] name = "diplomat-runtime" -version = "0.8.0" -source = "git+https://github.com/rust-diplomat/diplomat?rev=bcf0fc679266bb5ee0c7b25a371398158e81a7e1#bcf0fc679266bb5ee0c7b25a371398158e81a7e1" +version = "0.8.1" +source = "git+https://github.com/rust-diplomat/diplomat?rev=e12d47299c9a447730d30e8b7d8fcee1839d7d87#e12d47299c9a447730d30e8b7d8fcee1839d7d87" dependencies = [ "log", ] @@ -66,7 +66,7 @@ dependencies = [ [[package]] name = "diplomat_core" version = "0.8.0" -source = "git+https://github.com/rust-diplomat/diplomat?rev=bcf0fc679266bb5ee0c7b25a371398158e81a7e1#bcf0fc679266bb5ee0c7b25a371398158e81a7e1" +source = "git+https://github.com/rust-diplomat/diplomat?rev=e12d47299c9a447730d30e8b7d8fcee1839d7d87#e12d47299c9a447730d30e8b7d8fcee1839d7d87" dependencies = [ "lazy_static", "proc-macro2", @@ -111,8 +111,7 @@ dependencies = [ "calendrical_calculations", "displaydoc", "icu_calendar_data", - "icu_locid", - "icu_locid_transform", + "icu_locale_core", "icu_provider", "tinystr", "writeable", @@ -122,6 +121,10 @@ dependencies = [ [[package]] name = "icu_calendar_data" version = "1.5.0" +dependencies = [ + "icu_locale", + "icu_provider_baked", +] [[package]] name = "icu_capi" @@ -138,8 +141,8 @@ dependencies = [ "icu_decimal", "icu_experimental", "icu_list", - "icu_locid", - "icu_locid_transform", + "icu_locale", + "icu_locale_core", "icu_normalizer", "icu_plurals", "icu_properties", @@ -161,7 +164,7 @@ dependencies = [ "displaydoc", "icu_casemap_data", "icu_collections", - "icu_locid", + "icu_locale_core", "icu_properties", "icu_provider", "writeable", @@ -171,6 +174,9 @@ dependencies = [ [[package]] name = "icu_casemap_data" version = "1.5.0" +dependencies = [ + "icu_provider_baked", +] [[package]] name = "icu_collator" @@ -179,7 +185,6 @@ dependencies = [ "displaydoc", "icu_collator_data", "icu_collections", - "icu_locid_transform", "icu_normalizer", "icu_properties", "icu_provider", @@ -192,6 +197,10 @@ dependencies = [ [[package]] name = "icu_collator_data" version = "1.5.0" +dependencies = [ + "icu_locale", + "icu_provider_baked", +] [[package]] name = "icu_collections" @@ -213,8 +222,7 @@ dependencies = [ "icu_calendar", "icu_datetime_data", "icu_decimal", - "icu_locid", - "icu_locid_transform", + "icu_locale_core", "icu_plurals", "icu_provider", "icu_timezone", @@ -227,6 +235,10 @@ dependencies = [ [[package]] name = "icu_datetime_data" version = "1.5.0" +dependencies = [ + "icu_locale", + "icu_provider_baked", +] [[package]] name = "icu_decimal" @@ -235,7 +247,6 @@ dependencies = [ "displaydoc", "fixed_decimal", "icu_decimal_data", - "icu_locid_transform", "icu_provider", "writeable", ] @@ -243,6 +254,10 @@ dependencies = [ [[package]] name = "icu_decimal_data" version = "1.5.0" +dependencies = [ + "icu_locale", + "icu_provider_baked", +] [[package]] name = "icu_experimental" @@ -253,8 +268,8 @@ dependencies = [ "icu_collections", "icu_decimal", "icu_experimental_data", - "icu_locid", - "icu_locid_transform", + "icu_locale", + "icu_locale_core", "icu_normalizer", "icu_pattern", "icu_plurals", @@ -275,6 +290,10 @@ dependencies = [ [[package]] name = "icu_experimental_data" version = "0.1.0" +dependencies = [ + "icu_locale", + "icu_provider_baked", +] [[package]] name = "icu_list" @@ -282,7 +301,6 @@ version = "1.5.0" dependencies = [ "displaydoc", "icu_list_data", - "icu_locid_transform", "icu_provider", "regex-automata", "writeable", @@ -291,33 +309,40 @@ dependencies = [ [[package]] name = "icu_list_data" version = "1.5.0" +dependencies = [ + "icu_locale", + "icu_provider_baked", +] [[package]] -name = "icu_locid" +name = "icu_locale" version = "1.5.0" dependencies = [ "displaydoc", - "litemap", + "icu_locale_core", + "icu_locale_data", + "icu_provider", "tinystr", - "writeable", "zerovec", ] [[package]] -name = "icu_locid_transform" +name = "icu_locale_core" version = "1.5.0" dependencies = [ "displaydoc", - "icu_locid", - "icu_locid_transform_data", - "icu_provider", + "litemap", "tinystr", + "writeable", "zerovec", ] [[package]] -name = "icu_locid_transform_data" +name = "icu_locale_data" version = "1.5.0" +dependencies = [ + "icu_provider_baked", +] [[package]] name = "icu_normalizer" @@ -338,6 +363,9 @@ dependencies = [ [[package]] name = "icu_normalizer_data" version = "1.5.0" +dependencies = [ + "icu_provider_baked", +] [[package]] name = "icu_pattern" @@ -356,7 +384,6 @@ version = "1.5.0" dependencies = [ "displaydoc", "fixed_decimal", - "icu_locid_transform", "icu_plurals_data", "icu_provider", "zerovec", @@ -365,6 +392,10 @@ dependencies = [ [[package]] name = "icu_plurals_data" version = "1.5.0" +dependencies = [ + "icu_locale", + "icu_provider_baked", +] [[package]] name = "icu_properties" @@ -372,7 +403,6 @@ version = "1.5.0" dependencies = [ "displaydoc", "icu_collections", - "icu_locid_transform", "icu_properties_data", "icu_provider", "tinystr", @@ -383,13 +413,17 @@ dependencies = [ [[package]] name = "icu_properties_data" version = "1.5.0" +dependencies = [ + "icu_locale", + "icu_provider_baked", +] [[package]] name = "icu_provider" version = "1.5.0" dependencies = [ "displaydoc", - "icu_locid", + "icu_locale_core", "icu_provider_macros", "log", "stable_deref_trait", @@ -404,13 +438,21 @@ dependencies = [ name = "icu_provider_adapters" version = "1.5.0" dependencies = [ - "icu_locid", - "icu_locid_transform", + "icu_locale", "icu_provider", "tinystr", "zerovec", ] +[[package]] +name = "icu_provider_baked" +version = "1.5.0" +dependencies = [ + "icu_provider", + "writeable", + "zerotrie", +] + [[package]] name = "icu_provider_macros" version = "1.5.0" @@ -427,7 +469,7 @@ dependencies = [ "core_maths", "displaydoc", "icu_collections", - "icu_locid", + "icu_locale_core", "icu_provider", "icu_segmenter_data", "utf8_iter", @@ -437,6 +479,10 @@ dependencies = [ [[package]] name = "icu_segmenter_data" version = "1.5.0" +dependencies = [ + "icu_locale", + "icu_provider_baked", +] [[package]] name = "icu_timezone" @@ -454,6 +500,9 @@ dependencies = [ [[package]] name = "icu_timezone_data" version = "1.5.0" +dependencies = [ + "icu_provider_baked", +] [[package]] name = "itoa" @@ -489,12 +538,6 @@ version = "0.4.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" -[[package]] -name = "memchr" -version = "2.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" - [[package]] name = "num-bigint" version = "0.4.5" @@ -575,12 +618,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.2.0" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9368763f5a9b804326f3af749e16f9abf378d227bcdee7634b13d8f17793782" -dependencies = [ - "memchr", -] +checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" [[package]] name = "ryu" @@ -869,7 +909,7 @@ dependencies = [ [[package]] name = "zerovec" -version = "0.10.2" +version = "0.10.4" dependencies = [ "yoke", "zerofrom", @@ -878,7 +918,7 @@ dependencies = [ [[package]] name = "zerovec-derive" -version = "0.10.2" +version = "0.10.3" dependencies = [ "proc-macro2", "quote", @@ -909,6 +949,10 @@ version = "0.1.6" name = "icu" version = "1.5.0" +[[patch.unused]] +name = "icu4x-datagen" +version = "1.5.0" + [[patch.unused]] name = "icu4x_ecma402" version = "0.8.2" @@ -921,10 +965,6 @@ version = "0.0.0" name = "icu_codepointtrie_builder" version = "0.3.8" -[[patch.unused]] -name = "icu_datagen" -version = "1.5.0" - [[patch.unused]] name = "icu_freertos" version = "1.5.0" @@ -937,10 +977,22 @@ version = "0.2.0" name = "icu_provider_blob" version = "1.5.0" +[[patch.unused]] +name = "icu_provider_export" +version = "1.5.0" + [[patch.unused]] name = "icu_provider_fs" version = "1.5.0" +[[patch.unused]] +name = "icu_provider_registry" +version = "1.5.0" + +[[patch.unused]] +name = "icu_provider_source" +version = "1.5.0" + [[patch.unused]] name = "ixdtf" version = "0.2.0" diff --git a/tutorials/js-tiny/tiny.mjs b/tutorials/js-tiny/tiny.mjs index f25724bf08b..a1ecb958fd8 100644 --- a/tutorials/js-tiny/tiny.mjs +++ b/tutorials/js-tiny/tiny.mjs @@ -7,15 +7,15 @@ // See . delete globalThis.fetch; -import {Locale, DataProvider, FixedDecimalFormatter, FixedDecimal } from './lib/index.mjs'; +import {Locale, DataProvider, FixedDecimalFormatter, FixedDecimal, FixedDecimalGroupingStrategy } from './lib/index.mjs'; -const locale = Locale.create_from_string("bn"); -const provider = DataProvider.create_compiled(); +const locale = Locale.createFromString("bn"); +const provider = DataProvider.createCompiled(); -const format = FixedDecimalFormatter.create_with_grouping_strategy(provider, locale, "Auto"); +const format = FixedDecimalFormatter.createWithGroupingStrategy(provider, locale, FixedDecimalGroupingStrategy.Auto); -const decimal = FixedDecimal.create_from_i32(1000007); -decimal.multiply_pow10(-2); +const decimal = FixedDecimal.fromInteger(1000007); +decimal.multiplyPow10(-2); const result = format.format(decimal); console.log("Output is", result);