Skip to content

Commit

Permalink
Reexport bigdecimal (#341)
Browse files Browse the repository at this point in the history
This commit pub-uses `bigdecimal` so that consumers can use the `bigdecimal`
type without have explicit exact-version dependency.

`bigdecimal` is a `<1.0` library, and so cargo will pull in additional
copies of it by default, as semver says each release of a `<1.0` crate is
backwards incompatible. So, if a consumer of `ion-rust` didn't have the
exact right version, then the `TryFrom<Decimal> for BigDecimal`
implementation wouldn't be accessible.

Fixes #302

Co-authored-by: Marc Bowes <[email protected]>
  • Loading branch information
marcbowes and marcbowes authored Nov 17, 2021
1 parent 630fb84 commit 480e4e1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,10 @@ pub use reader::Reader;
pub use symbol_table::SymbolTable;
pub use system_event_handler::SystemEventHandler;
pub use types::IonType;

/// Re-exports of third party dependencies that are part of our public API.
///
/// See also: https://github.com/amzn/ion-rust/issues/302.
pub mod external {
pub use bigdecimal;
}
17 changes: 17 additions & 0 deletions tests/reexport_external.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use std::convert::TryInto;

use ion_rs::external::bigdecimal::{BigDecimal, Zero};
use ion_rs::types::decimal::Decimal;

/// This test shows how the ion_rs integration with bigdecimal can be used
/// through a reexport. This means that consumers of ion_rs can use this
/// integration without having to specify the exact depdendency version.
///
/// See also: https://github.com/amzn/ion-rust/issues/302.
#[test]
fn bigdecimal_is_reexported() {
let ion_rs_type = Decimal::new(0, 0);
let integration_type: BigDecimal = ion_rs_type.try_into().expect("not negative zero");

assert_eq!((Zero::zero(), 0), integration_type.as_bigint_and_exponent())
}

0 comments on commit 480e4e1

Please sign in to comment.