Skip to content
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: test
args: --no-default-features --features "colored, float-cmp, num-bigint, rust-decimal"
args: --no-default-features --features "colored, float-cmp, num-bigint, rust-decimal, bigdecimal"

msrv:
name: Build with MSRV
Expand Down
8 changes: 5 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,25 @@ rustdoc-args = ["--cfg", "docsrs"]

[features]
default = ["std", "colored", "float-cmp", "panic", "regex"]
bigdecimal = ["dep:bigdecimal"]
colored = ["dep:sdiff"]
float-cmp = ["dep:float-cmp"]
num-bigint = ["dep:num-bigint", "dep:lazy_static"]
rust-decimal = ["dep:rust_decimal"]
panic = ["std"]
regex = ["dep:regex"]
std = []
std = ["bigdecimal/std", "rust_decimal/std"]

[dependencies]
hashbrown = "0.15"

# optional
bigdecimal = { version = "0.4", optional = true, default-features = false }
float-cmp = { version = "0.10", optional = true }
lazy_static = { version = "1", optional = true }
num-bigint = { version = "0.4", default-features = false, optional = true }
rust_decimal = { version = "1", default-features = false, optional = true }
num-bigint = { version = "0.4", optional = true, default-features = false }
regex = { version = "1", optional = true }
rust_decimal = { version = "1", optional = true, default-features = false }
sdiff = { version = "0.1", optional = true }

[dev-dependencies]
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ for numbers of types
* integer primitives: `i8`, `i16`, `i32`, `i64`, `i128` and `isize`
* floating point numbers: `f32` and `f64`
* `num_bigint::BigInt` (requires crate feature `num-bigint`)
* `bigdecimal:BigDecimal` and `bigdecimal:BigDecimalRef` (requires crate feature `bigdecimal`)
* `rust_decimal::Decimal` (requires crate feature `rust-decimal`)

| assertion | description |
|-----------------|------------------------------------------------------|
Expand All @@ -182,6 +184,7 @@ for numbers of types
and `usize`
* floating point numbers: `f32` and `f64`
* `num_bigint::BigInt` and `num_bigint::BigUint` (requires crate feature `num-bigint`)
* `bigdecimal:BigDecimal` and `bigdecimal:BigDecimalRef` (requires crate feature `bigdecimal`)
* `rust_decimal::Decimal` (requires crate feature `rust-decimal`)

| assertion | description |
Expand Down
2 changes: 2 additions & 0 deletions examples/fixture/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Rust issue [#95513](https://github.com/rust-lang/rust/issues/95513) is fixed
mod dummy_extern_uses {
use anyhow as _;
#[cfg(feature = "bigdecimal")]
use bigdecimal as _;
#[cfg(feature = "float-cmp")]
use float_cmp as _;
use hashbrown as _;
Expand Down
4 changes: 2 additions & 2 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ lint-all-features:

# linting code using Clippy for no-std environment
lint-no-std:
cargo clippy --all-targets --no-default-features --features "colored, float-cmp, num-bigint, rust-decimal"
cargo clippy --all-targets --no-default-features --features "colored, float-cmp, num-bigint, rust-decimal, bigdecimal"

# linting code using Clippy with no features enabled
lint-no-features:
Expand All @@ -55,7 +55,7 @@ test-all-features:

# run tests for no-std environment
test-no-std:
cargo test --no-default-features --features "colored, float-cmp, num-bigint, rust-decimal"
cargo test --no-default-features --features "colored, float-cmp, num-bigint, rust-decimal, bigdecimal"

# run tests with no features enabled
test-no-features:
Expand Down
78 changes: 78 additions & 0 deletions src/bigdecimal/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
use crate::properties::{AdditiveIdentityProperty, MultiplicativeIdentityProperty, SignumProperty};
use bigdecimal::num_bigint::Sign;
use bigdecimal::{BigDecimal, BigDecimalRef, One, Zero};
use lazy_static::lazy_static;

lazy_static! {
static ref BIGDECIMAL_ZERO: BigDecimal = bigdecimal_zero();
static ref BIGDECIMAL_ONE: BigDecimal = bigdecimal_one();
}

#[inline]
fn bigdecimal_zero() -> BigDecimal {
BigDecimal::zero()
}

#[inline]
fn bigdecimal_one() -> BigDecimal {
BigDecimal::one()
}

impl SignumProperty for BigDecimal {
fn is_negative_property(&self) -> bool {
self.sign() == Sign::Minus
}

fn is_positive_property(&self) -> bool {
self.sign() == Sign::Plus
}
}

impl AdditiveIdentityProperty for BigDecimal {
fn additive_identity() -> Self {
bigdecimal_zero()
}
}

impl AdditiveIdentityProperty for &BigDecimal {
fn additive_identity() -> Self {
&BIGDECIMAL_ZERO
}
}

impl MultiplicativeIdentityProperty for BigDecimal {
fn multiplicative_identity() -> Self {
bigdecimal_one()
}
}

impl MultiplicativeIdentityProperty for &BigDecimal {
fn multiplicative_identity() -> Self {
&BIGDECIMAL_ONE
}
}

impl SignumProperty for BigDecimalRef<'_> {
fn is_negative_property(&self) -> bool {
self.sign() == Sign::Minus
}

fn is_positive_property(&self) -> bool {
self.sign() == Sign::Plus
}
}

impl AdditiveIdentityProperty for BigDecimalRef<'_> {
fn additive_identity() -> Self {
BIGDECIMAL_ZERO.to_ref()
}
}

impl MultiplicativeIdentityProperty for BigDecimalRef<'_> {
fn multiplicative_identity() -> Self {
BIGDECIMAL_ONE.to_ref()
}
}

#[cfg(test)]
mod tests;
Loading
Loading