Skip to content

Commit

Permalink
work around rust-diplomat/diplomat#173, diplomat-gen
Browse files Browse the repository at this point in the history
  • Loading branch information
eggrobin committed Jun 15, 2022
1 parent 2999f65 commit cd6f3a3
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 125 deletions.
3 changes: 1 addition & 2 deletions ffi/diplomat/c/include/ICU4XFixedDecimalFormatOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@
extern "C" {
#endif
#include "ICU4XFixedDecimalGroupingStrategy.h"
#include "ICU4XFixedDecimalSignDisplay.h"

typedef struct ICU4XFixedDecimalFormatOptions {
ICU4XFixedDecimalGroupingStrategy grouping_strategy;
ICU4XFixedDecimalSignDisplay sign_display;
int8_t work_around_diplomat_issue_173_do_not_use_this_field;
} ICU4XFixedDecimalFormatOptions;

ICU4XFixedDecimalFormatOptions ICU4XFixedDecimalFormatOptions_default();
Expand Down
26 changes: 0 additions & 26 deletions ffi/diplomat/c/include/ICU4XFixedDecimalSignDisplay.h

This file was deleted.

14 changes: 1 addition & 13 deletions ffi/diplomat/cpp/docs/source/decimal_ffi.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

.. cpp:member:: ICU4XFixedDecimalGroupingStrategy grouping_strategy

.. cpp:member:: ICU4XFixedDecimalSignDisplay sign_display
.. cpp:member:: int8_t work_around_diplomat_issue_173_do_not_use_this_field

.. cpp:function:: static ICU4XFixedDecimalFormatOptions default_()

Expand All @@ -43,15 +43,3 @@
.. cpp:enumerator:: Always

.. cpp:enumerator:: Min2

.. cpp:enum-struct:: ICU4XFixedDecimalSignDisplay

.. cpp:enumerator:: Auto

.. cpp:enumerator:: Never

.. cpp:enumerator:: Always

.. cpp:enumerator:: ExceptZero

.. cpp:enumerator:: Negative
4 changes: 2 additions & 2 deletions ffi/diplomat/cpp/include/ICU4XFixedDecimalFormat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class ICU4XFixedDecimalFormat {

inline diplomat::result<ICU4XFixedDecimalFormat, ICU4XError> ICU4XFixedDecimalFormat::try_new(const ICU4XLocale& locale, const ICU4XDataProvider& provider, ICU4XFixedDecimalFormatOptions options) {
ICU4XFixedDecimalFormatOptions diplomat_wrapped_struct_options = options;
auto diplomat_result_raw_out_value = capi::ICU4XFixedDecimalFormat_try_new(locale.AsFFI(), provider.AsFFI(), capi::ICU4XFixedDecimalFormatOptions{ .grouping_strategy = static_cast<capi::ICU4XFixedDecimalGroupingStrategy>(diplomat_wrapped_struct_options.grouping_strategy), .sign_display = static_cast<capi::ICU4XFixedDecimalSignDisplay>(diplomat_wrapped_struct_options.sign_display) });
auto diplomat_result_raw_out_value = capi::ICU4XFixedDecimalFormat_try_new(locale.AsFFI(), provider.AsFFI(), capi::ICU4XFixedDecimalFormatOptions{ .grouping_strategy = static_cast<capi::ICU4XFixedDecimalGroupingStrategy>(diplomat_wrapped_struct_options.grouping_strategy), .work_around_diplomat_issue_173_do_not_use_this_field = diplomat_wrapped_struct_options.work_around_diplomat_issue_173_do_not_use_this_field });
diplomat::result<ICU4XFixedDecimalFormat, ICU4XError> diplomat_result_out_value;
if (diplomat_result_raw_out_value.is_ok) {
diplomat_result_out_value = diplomat::Ok(ICU4XFixedDecimalFormat(diplomat_result_raw_out_value.ok));
Expand All @@ -96,7 +96,7 @@ inline diplomat::result<ICU4XFixedDecimalFormat, ICU4XError> ICU4XFixedDecimalFo
}
inline diplomat::result<ICU4XFixedDecimalFormat, ICU4XError> ICU4XFixedDecimalFormat::try_new_from_decimal_symbols_v1(const ICU4XDataStruct& data_struct, ICU4XFixedDecimalFormatOptions options) {
ICU4XFixedDecimalFormatOptions diplomat_wrapped_struct_options = options;
auto diplomat_result_raw_out_value = capi::ICU4XFixedDecimalFormat_try_new_from_decimal_symbols_v1(data_struct.AsFFI(), capi::ICU4XFixedDecimalFormatOptions{ .grouping_strategy = static_cast<capi::ICU4XFixedDecimalGroupingStrategy>(diplomat_wrapped_struct_options.grouping_strategy), .sign_display = static_cast<capi::ICU4XFixedDecimalSignDisplay>(diplomat_wrapped_struct_options.sign_display) });
auto diplomat_result_raw_out_value = capi::ICU4XFixedDecimalFormat_try_new_from_decimal_symbols_v1(data_struct.AsFFI(), capi::ICU4XFixedDecimalFormatOptions{ .grouping_strategy = static_cast<capi::ICU4XFixedDecimalGroupingStrategy>(diplomat_wrapped_struct_options.grouping_strategy), .work_around_diplomat_issue_173_do_not_use_this_field = diplomat_wrapped_struct_options.work_around_diplomat_issue_173_do_not_use_this_field });
diplomat::result<ICU4XFixedDecimalFormat, ICU4XError> diplomat_result_out_value;
if (diplomat_result_raw_out_value.is_ok) {
diplomat_result_out_value = diplomat::Ok(ICU4XFixedDecimalFormat(diplomat_result_raw_out_value.ok));
Expand Down
3 changes: 1 addition & 2 deletions ffi/diplomat/cpp/include/ICU4XFixedDecimalFormatOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@
extern "C" {
#endif
#include "ICU4XFixedDecimalGroupingStrategy.h"
#include "ICU4XFixedDecimalSignDisplay.h"

typedef struct ICU4XFixedDecimalFormatOptions {
ICU4XFixedDecimalGroupingStrategy grouping_strategy;
ICU4XFixedDecimalSignDisplay sign_display;
int8_t work_around_diplomat_issue_173_do_not_use_this_field;
} ICU4XFixedDecimalFormatOptions;

ICU4XFixedDecimalFormatOptions ICU4XFixedDecimalFormatOptions_default();
Expand Down
5 changes: 2 additions & 3 deletions ffi/diplomat/cpp/include/ICU4XFixedDecimalFormatOptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ namespace capi {
}

#include "ICU4XFixedDecimalGroupingStrategy.hpp"
#include "ICU4XFixedDecimalSignDisplay.hpp"
struct ICU4XFixedDecimalFormatOptions;

/**
Expand All @@ -28,13 +27,13 @@ struct ICU4XFixedDecimalFormatOptionsDeleter {
struct ICU4XFixedDecimalFormatOptions {
public:
ICU4XFixedDecimalGroupingStrategy grouping_strategy;
ICU4XFixedDecimalSignDisplay sign_display;
int8_t work_around_diplomat_issue_173_do_not_use_this_field;
static ICU4XFixedDecimalFormatOptions default_();
};


inline ICU4XFixedDecimalFormatOptions ICU4XFixedDecimalFormatOptions::default_() {
capi::ICU4XFixedDecimalFormatOptions diplomat_raw_struct_out_value = capi::ICU4XFixedDecimalFormatOptions_default();
return ICU4XFixedDecimalFormatOptions{ .grouping_strategy = std::move(static_cast<ICU4XFixedDecimalGroupingStrategy>(diplomat_raw_struct_out_value.grouping_strategy)), .sign_display = std::move(static_cast<ICU4XFixedDecimalSignDisplay>(diplomat_raw_struct_out_value.sign_display)) };
return ICU4XFixedDecimalFormatOptions{ .grouping_strategy = std::move(static_cast<ICU4XFixedDecimalGroupingStrategy>(diplomat_raw_struct_out_value.grouping_strategy)), .work_around_diplomat_issue_173_do_not_use_this_field = std::move(diplomat_raw_struct_out_value.work_around_diplomat_issue_173_do_not_use_this_field) };
}
#endif
26 changes: 0 additions & 26 deletions ffi/diplomat/cpp/include/ICU4XFixedDecimalSignDisplay.h

This file was deleted.

25 changes: 0 additions & 25 deletions ffi/diplomat/cpp/include/ICU4XFixedDecimalSignDisplay.hpp

This file was deleted.

3 changes: 3 additions & 0 deletions ffi/diplomat/src/decimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ pub mod ffi {

pub struct ICU4XFixedDecimalFormatOptions {
pub grouping_strategy: ICU4XFixedDecimalGroupingStrategy,
// JS code generation does not support single-field structures.
// See https://github.com/rust-diplomat/diplomat/issues/173.
work_around_diplomat_issue_173_do_not_use_this_field: i8,
}

impl ICU4XFixedDecimalFormatOptions {
Expand Down
4 changes: 1 addition & 3 deletions ffi/diplomat/wasm/docs/decimal_ffi.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@

.. js:attribute:: grouping_strategy

.. js:attribute:: sign_display
.. js:attribute:: work_around_diplomat_issue_173_do_not_use_this_field

.. js:staticfunction:: default()

.. js:class:: ICU4XFixedDecimalGroupingStrategy

.. js:class:: ICU4XFixedDecimalSignDisplay
31 changes: 8 additions & 23 deletions ffi/diplomat/wasm/lib/api.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ export class ICU4XFixedDecimalFormat {

static try_new(locale, provider, options) {
const diplomat_ICU4XFixedDecimalFormatOptions_extracted_grouping_strategy = options["grouping_strategy"];
const diplomat_ICU4XFixedDecimalFormatOptions_extracted_sign_display = options["sign_display"];
const diplomat_ICU4XFixedDecimalFormatOptions_extracted_work_around_diplomat_issue_173_do_not_use_this_field = options["work_around_diplomat_issue_173_do_not_use_this_field"];
const diplomat_out = (() => {
const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4);
const result_tag = {};
Expand All @@ -755,7 +755,7 @@ export class ICU4XFixedDecimalFormat {
size: 5,
align: 4,
});
wasm.ICU4XFixedDecimalFormat_try_new(diplomat_receive_buffer, locale.underlying, provider.underlying, ICU4XFixedDecimalGroupingStrategy_js_to_rust[diplomat_ICU4XFixedDecimalFormatOptions_extracted_grouping_strategy], ICU4XFixedDecimalSignDisplay_js_to_rust[diplomat_ICU4XFixedDecimalFormatOptions_extracted_sign_display]);
wasm.ICU4XFixedDecimalFormat_try_new(diplomat_receive_buffer, locale.underlying, provider.underlying, ICU4XFixedDecimalGroupingStrategy_js_to_rust[diplomat_ICU4XFixedDecimalFormatOptions_extracted_grouping_strategy], diplomat_ICU4XFixedDecimalFormatOptions_extracted_work_around_diplomat_issue_173_do_not_use_this_field);
const is_ok = (new Uint8Array(wasm.memory.buffer, diplomat_receive_buffer + 4, 1))[0] == 1;
if (is_ok) {
const ok_value = (() => {
Expand All @@ -774,7 +774,7 @@ export class ICU4XFixedDecimalFormat {

static try_new_from_decimal_symbols_v1(data_struct, options) {
const diplomat_ICU4XFixedDecimalFormatOptions_extracted_grouping_strategy = options["grouping_strategy"];
const diplomat_ICU4XFixedDecimalFormatOptions_extracted_sign_display = options["sign_display"];
const diplomat_ICU4XFixedDecimalFormatOptions_extracted_work_around_diplomat_issue_173_do_not_use_this_field = options["work_around_diplomat_issue_173_do_not_use_this_field"];
const diplomat_out = (() => {
const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4);
const result_tag = {};
Expand All @@ -783,7 +783,7 @@ export class ICU4XFixedDecimalFormat {
size: 5,
align: 4,
});
wasm.ICU4XFixedDecimalFormat_try_new_from_decimal_symbols_v1(diplomat_receive_buffer, data_struct.underlying, ICU4XFixedDecimalGroupingStrategy_js_to_rust[diplomat_ICU4XFixedDecimalFormatOptions_extracted_grouping_strategy], ICU4XFixedDecimalSignDisplay_js_to_rust[diplomat_ICU4XFixedDecimalFormatOptions_extracted_sign_display]);
wasm.ICU4XFixedDecimalFormat_try_new_from_decimal_symbols_v1(diplomat_receive_buffer, data_struct.underlying, ICU4XFixedDecimalGroupingStrategy_js_to_rust[diplomat_ICU4XFixedDecimalFormatOptions_extracted_grouping_strategy], diplomat_ICU4XFixedDecimalFormatOptions_extracted_work_around_diplomat_issue_173_do_not_use_this_field);
const is_ok = (new Uint8Array(wasm.memory.buffer, diplomat_receive_buffer + 4, 1))[0] == 1;
if (is_ok) {
const ok_value = (() => {
Expand Down Expand Up @@ -836,12 +836,12 @@ export class ICU4XFixedDecimalFormatOptions {

static default() {
const diplomat_out = (() => {
const diplomat_receive_buffer = wasm.diplomat_alloc(8, 4);
const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4);
wasm.ICU4XFixedDecimalFormatOptions_default(diplomat_receive_buffer);
const out = new ICU4XFixedDecimalFormatOptions(diplomat_receive_buffer);
diplomat_alloc_destroy_registry.register(out, {
ptr: out.underlying,
size: 8,
size: 5,
align: 4,
});
return out;
Expand All @@ -853,8 +853,8 @@ export class ICU4XFixedDecimalFormatOptions {
return ICU4XFixedDecimalGroupingStrategy_rust_to_js[(new Int32Array(wasm.memory.buffer, this.underlying + 0, 1))[0]];
}

get sign_display() {
return ICU4XFixedDecimalSignDisplay_rust_to_js[(new Int32Array(wasm.memory.buffer, this.underlying + 4, 1))[0]];
get work_around_diplomat_issue_173_do_not_use_this_field() {
return (new Int8Array(wasm.memory.buffer, this.underlying + 4, 1))[0];
}
}

Expand Down Expand Up @@ -891,21 +891,6 @@ const ICU4XFixedDecimalSign_rust_to_js = {
2: "Positive",
};

const ICU4XFixedDecimalSignDisplay_js_to_rust = {
"Auto": 0,
"Never": 1,
"Always": 2,
"ExceptZero": 3,
"Negative": 4,
};
const ICU4XFixedDecimalSignDisplay_rust_to_js = {
0: "Auto",
1: "Never",
2: "Always",
3: "ExceptZero",
4: "Negative",
};

const ICU4XLineBreakIteratorLatin1_box_destroy_registry = new FinalizationRegistry(underlying => {
wasm.ICU4XLineBreakIteratorLatin1_destroy(underlying);
});
Expand Down

0 comments on commit cd6f3a3

Please sign in to comment.