Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce RoundingIncrement to FixedDecimal #4219

Merged
merged 3 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ffi/capi/c/include/ICU4XFixedDecimal.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions ffi/capi/c/include/ICU4XRoundingIncrement.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions ffi/capi/cpp/docs/source/fixed_decimal_ffi.rst

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions ffi/capi/cpp/include/ICU4XFixedDecimal.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions ffi/capi/cpp/include/ICU4XFixedDecimal.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions ffi/capi/cpp/include/ICU4XRoundingIncrement.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions ffi/capi/cpp/include/ICU4XRoundingIncrement.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions ffi/capi/js/docs/source/fixed_decimal_ffi.rst

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions ffi/capi/js/include/ICU4XFixedDecimal.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions ffi/capi/js/include/ICU4XFixedDecimal.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions ffi/capi/js/include/ICU4XRoundingIncrement.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions ffi/capi/js/include/ICU4XRoundingIncrement.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ffi/capi/js/include/index.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ffi/capi/js/include/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions ffi/capi/src/fixed_decimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

use fixed_decimal::RoundingIncrement;
use fixed_decimal::Sign;
use fixed_decimal::SignDisplay;

Expand Down Expand Up @@ -38,6 +39,15 @@ pub mod ffi {
Negative,
}

/// Increment used in a rounding operation.
#[diplomat::rust_link(fixed_decimal::RoundingIncrement, Enum)]
pub enum ICU4XRoundingIncrement {
MultiplesOf1,
MultiplesOf2,
MultiplesOf5,
MultiplesOf25,
}

impl ICU4XFixedDecimal {
/// Construct an [`ICU4XFixedDecimal`] from an integer.
#[diplomat::rust_link(fixed_decimal::FixedDecimal, Struct)]
Expand Down Expand Up @@ -220,6 +230,16 @@ pub mod ffi {
self.0.trunc(position)
}

#[diplomat::rust_link(fixed_decimal::FixedDecimal::trunc_to_increment, FnInStruct)]
#[diplomat::rust_link(
fixed_decimal::FixedDecimal::trunced_to_increment,
FnInStruct,
hidden
)]
pub fn trunc_to_increment(&mut self, position: i16, increment: ICU4XRoundingIncrement) {
self.0.trunc_to_increment(position, increment.into())
}

#[diplomat::rust_link(fixed_decimal::FixedDecimal::half_trunc, FnInStruct)]
#[diplomat::rust_link(fixed_decimal::FixedDecimal::half_trunced, FnInStruct, hidden)]
pub fn half_trunc(&mut self, position: i16) {
Expand Down Expand Up @@ -321,3 +341,14 @@ impl From<ffi::ICU4XFixedDecimalSignDisplay> for SignDisplay {
}
}
}

impl From<ffi::ICU4XRoundingIncrement> for RoundingIncrement {
fn from(value: ffi::ICU4XRoundingIncrement) -> Self {
match value {
ffi::ICU4XRoundingIncrement::MultiplesOf1 => RoundingIncrement::MultiplesOf1,
ffi::ICU4XRoundingIncrement::MultiplesOf2 => RoundingIncrement::MultiplesOf2,
ffi::ICU4XRoundingIncrement::MultiplesOf5 => RoundingIncrement::MultiplesOf5,
ffi::ICU4XRoundingIncrement::MultiplesOf25 => RoundingIncrement::MultiplesOf25,
}
}
}
Loading