Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: paupino/rust-decimal
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 1.36.0
Choose a base ref
...
head repository: paupino/rust-decimal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 1.37.0
Choose a head ref
  • 18 commits
  • 38 files changed
  • 10 contributors

Commits on Sep 10, 2024

  1. Update Cargo.toml

    Dylan-DPC authored Sep 10, 2024
    Copy the full SHA
    5bba9eb View commit details

Commits on Sep 18, 2024

  1. Merge pull request #677 from Dylan-DPC/patch-1

    Update Cargo.toml
    Tony-Samuels authored Sep 18, 2024
    Copy the full SHA
    dfd84a5 View commit details
  2. Fix f64 dec limit edge case (#678)

    ---
    Co-authored-by: Paul Mason <paul@paulmason.me>
    finnbear authored Sep 18, 2024
    Copy the full SHA
    ca982d6 View commit details

Commits on Sep 30, 2024

  1. Copy the full SHA
    f14f1b6 View commit details
  2. maths is private: rust_decimal::maths::MathematicalOps -> rust_decima…

    …l::MathematicalOps
    olgabot authored Sep 30, 2024
    Copy the full SHA
    9e3195b View commit details

Commits on Oct 4, 2024

  1. Rkyv 0.8 example (#683)

    * add rkyv-0.8 example
    * fix clippy errors
    ---------
    Co-authored-by: Tony Samuels <tonysamuels@protonmail.com>
    Tony-Samuels authored Oct 4, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    7ae131e View commit details

Commits on Oct 8, 2024

  1. Run

    olgabot committed Oct 8, 2024
    Copy the full SHA
    03eb303 View commit details

Commits on Oct 9, 2024

  1. Merge branch 'master' into patch-1

    paupino authored Oct 9, 2024
    Copy the full SHA
    03f2c29 View commit details
  2. Merge pull request #681 from olgabot/patch-1

    Add explanation of how to enable `maths` feature
    Tony-Samuels authored Oct 9, 2024
    Copy the full SHA
    fa88579 View commit details

Commits on Oct 15, 2024

  1. Create pub constant Decimal::MAX_SCALE (#685)

    Tony-Samuels authored Oct 15, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    46fb4c3 View commit details

Commits on Feb 21, 2025

  1. Fix panic when parsing improper scientific notation. (#700)

    schungx authored Feb 21, 2025

    Verified

    This commit was signed with the committer’s verified signature.
    cleptric Michi Hoffmann
    Copy the full SHA
    722af9f View commit details

Commits on Feb 23, 2025

  1. Clean up tests to use Ok/Err format (#703)

    paupino authored Feb 23, 2025

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    acffc43 View commit details
  2. Add dec!() macro by example (#692)

    * add dec! macro by example
    * Cargo fmt
    * Fixes no_std support and minimum Rust version
    * Minimum Rust version changes
    
    ---------
    
    Co-authored-by: Daniel Pfeiffer <dpfeiffer@amadeus.com>
    Co-authored-by: Paul Mason <paul@paulmason.me>
    3 people authored Feb 23, 2025

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    9689971 View commit details
  3. feat: add rand-0_9 crate feature (#702)

    * feat: add rand-0_9 crate feature
    * Added rand 0.9 test into build system
    
    ---------
    
    Co-authored-by: Paul Mason <paul@paulmason.me>
    robjtede and paupino authored Feb 23, 2025
    Copy the full SHA
    41ce632 View commit details

Commits on Mar 5, 2025

  1. Reduce required mysql dependencies for diesel (#707)

    * Cargo.toml:  Only enable mysql_backend on diesel, not the whole mysql feature
    * Cargo.toml:  Add diesel with mysql feature enabled to dev-dependencies
    mcronce authored Mar 5, 2025
    Copy the full SHA
    f34cefc View commit details

Commits on Mar 17, 2025

  1. Refactor macro for backwards compatability (#711)

    * Refactor macros for backwards compatibility
    * Fixes documentation and example compilation
    * Refactor macros for backwards compatibility
    * Update changelog to note going forward process
    * Fixes incorrect lifetime removal
    paupino authored Mar 17, 2025
    Copy the full SHA
    ad97454 View commit details
  2. Specify fixed version for macros dependency (#712)

    paupino authored Mar 17, 2025
    Copy the full SHA
    39fe37e View commit details
  3. Specify fixed version for macros dependency

    paupino committed Mar 17, 2025
    Copy the full SHA
    ffe9495 View commit details
2 changes: 1 addition & 1 deletion .buildnumber
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
1
36
37
0
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -59,7 +59,7 @@ jobs:

- uses: dtolnay/rust-toolchain@stable
with:
toolchain: 1.60.0
toolchain: 1.67.1

- name: Cache cargo registry
uses: actions/cache@v4
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Version History

**Please see [Github Releases](https://github.com/paupino/rust-decimal/releases) for version history going forward.**

# 1.36.0

### Fixed
27 changes: 17 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -11,8 +11,8 @@ license = "MIT"
name = "rust_decimal"
readme = "./README.md"
repository = "https://github.com/paupino/rust-decimal"
rust-version = "1.60"
version = "1.36.0"
rust-version = "1.67.1"
version = "1.37.0"

[package.metadata.docs.rs]
all-features = true
@@ -23,15 +23,16 @@ arbitrary = { default-features = false, optional = true, version = "1.0" }
arrayvec = { default-features = false, version = "0.7" }
borsh = { default-features = false, features = ["derive", "unstable__schema"], optional = true, version = "1.1.1" }
bytes = { default-features = false, optional = true, version = "1.0" }
diesel = { default-features = false, optional = true, version = "2.2" }
diesel = { default-features = false, optional = true, version = "2.2.3" }
ndarray = { default-features = false, optional = true, version = "0.15.6" }
num-traits = { default-features = false, features = ["i128"], version = "0.2" }
postgres-types = { default-features = false, optional = true, version = "0.2" }
proptest = { default-features = false, optional = true, features = ["std"], version = "1.0" }
rand = { default-features = false, optional = true, version = "0.8" }
rand-0_9 = { default-features = false, optional = true, package = "rand", version = "0.9" }
rust_decimal_macros = { path = "macros", default-features = false, optional = true, version = "1" }
rkyv = { default-features = false, features = ["size_32", "std"], optional = true, version = "0.7.42" }
rocket = { default-features = false, optional = true, version = "0.5.0-rc.3" }
#rust_decimal_macros = { default-features = false, optional = true, version = "1.34" } # This needs to a published version
serde = { default-features = false, optional = true, version = "1.0" }
serde_json = { default-features = false, optional = true, version = "1.0" }
tokio-postgres = { default-features = false, optional = true, version = "0.7" }
@@ -41,9 +42,12 @@ bincode = { default-features = false, version = "1.0" }
bytes = { default-features = false, version = "1.0" }
criterion = { default-features = false, version = "0.5" }
csv = "1"
diesel = { default-features = false, features = ["mysql"], version = "2.2.3" }
futures = { default-features = false, version = "0.3" }
rand = { default-features = false, features = ["getrandom"], version = "0.8" }
rust_decimal_macros = { default-features = false, version = "1.33" }
rand-0_9 = { default-features = false, features = ["thread_rng"], package = "rand", version = "0.9" }
rkyv-0_8 = { version = "0.8", package = "rkyv" }
rust_decimal_macros = { path = "macros" }
serde = { default-features = false, features = ["derive"], version = "1.0" }
serde_json = "1.0"
tokio = { default-features = false, features = ["macros", "rt-multi-thread", "test-util"], version = "1.0" }
@@ -53,26 +57,25 @@ tokio-postgres = { default-features = false, version = "0.7" }

[features]
default = ["serde", "std"]
# Removed in 1.34.2 due to an issue during version resolution
#macros = ["dep:rust_decimal_macros"]

borsh = ["dep:borsh", "std"]
c-repr = [] # Force Decimal to be repr(C)
db-diesel-mysql = ["diesel/mysql", "std"]
db-diesel-mysql = ["diesel/mysql_backend", "std"]
db-diesel-postgres = ["diesel/postgres", "std"]
db-diesel2-mysql = ["db-diesel-mysql"]
db-diesel2-postgres = ["db-diesel-postgres"]
db-postgres = ["dep:bytes", "dep:postgres-types", "std"]
db-tokio-postgres = ["dep:bytes", "dep:postgres-types", "std"]
legacy-ops = []
macros = ["dep:rust_decimal_macros"]
maths = []
maths-nopanic = ["maths"]
ndarray = ["dep:ndarray"]
proptest = ["dep:proptest"]
rand = ["dep:rand"]
rkyv = ["dep:rkyv"]
rkyv-safe = ["rkyv/validation"]
rocket-traits = ["dep:rocket"]
rocket-traits = ["dep:rocket", "std"]
rust-fuzz = ["dep:arbitrary"]
serde = ["dep:serde"]
serde-arbitrary-precision = ["serde-with-arbitrary-precision"]
@@ -90,9 +93,13 @@ harness = false
name = "comparison"
path = "benches/comparison.rs"

[[example]]
name = "rkyv-remote"
required-features = ["macros"]

[workspace]
members = [
".",
"./macros"
"./macros",
]
resolver = "2"
36 changes: 19 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -25,28 +25,23 @@ can be truncated using the `normalize` or `round_dp` functions.
$ cargo add rust_decimal
```

In addition, if you would like to use the optimized macro for convenient creation of decimals:

```sh
$ cargo add rust_decimal_macros
```

Alternatively, you can edit your `Cargo.toml` directly and run `cargo update`:

```toml
[dependencies]
rust_decimal = "1.36"
rust_decimal_macros = "1.36"
rust_decimal = "1.37"
```

## Usage

Decimal numbers can be created in a few distinct ways. The easiest and most efficient method of creating a Decimal is to
use the procedural macro that can be enabled using the `macros` feature:
use the macro:

```rust
// Import the `rust_decimal_macros` crate and use the macro directly from there.
use rust_decimal_macros::dec;
// Import via use rust_decimal_macros or use the `macros` feature to import at the crate level
// `use rust_decimal_macros::dec;`
// or
// `use rust_decimal::dec;`

let number = dec!(-1.23) + dec!(3.45);
assert_eq!(number, dec!(2.22));
@@ -87,13 +82,16 @@ assert_eq!("3", my_int.to_string());
// Using the raw decimal representation
let pi = Decimal::from_parts(1_102_470_952, 185_874_565, 1_703_060_790, false, 28);
assert_eq!("3.1415926535897932384626433832", pi.to_string());

// If the `macros` feature is enabled, it also allows for the `dec!` macro
let amount = dec!(25.12);
assert_eq!("25.12", amount.to_string());
```

Once you have instantiated your `Decimal` number you can perform calculations with it just like any other number:

```rust
use rust_decimal::prelude::*;
use rust_decimal_macros::dec;
use rust_decimal::prelude::*; // Includes the `dec` macro when feature specified

let amount = dec!(25.12);
let tax_percentage = dec!(0.085);
@@ -195,9 +193,15 @@ two).

### `rkyv`

Enables [rkyv](https://github.com/rkyv/rkyv) serialization for `Decimal`.
Enables [rkyv](https://github.com/rkyv/rkyv) serialization for `Decimal`. In order to avoid breaking changes, this is
currently locked at version `0.7`.

Supports rkyv's safe API when the `rkyv-safe` feature is enabled as well.

If `rkyv` support for versions `0.8` of greater is desired, `rkyv`'
s [remote derives](https://rkyv.org/derive-macro-features/remote-derive.html) should be used instead. See
`examples/rkyv-remote`.

### `rocket-traits`

Enable support for Rocket forms by implementing the `FromFormField` trait.
@@ -365,9 +369,7 @@ Please refer to the [Build document](BUILD.md) for more information on building

## Minimum Rust Compiler Version

The current _minimum_ compiler version
is [`1.60.0`](https://github.com/rust-lang/rust/blob/master/RELEASES.md#version-1600-2022-04-07)
which was released on `2022-04-07`.
The current _minimum_ compiler version is `1.67.1` which was released on `2023-02-09`.

This library maintains support for rust compiler versions that are 4 minor versions away from the current stable rust
compiler version.
13 changes: 8 additions & 5 deletions build.rs
Original file line number Diff line number Diff line change
@@ -37,13 +37,16 @@ fn prepare(readme: &str) -> Result<String, Box<dyn std::error::Error>> {
"(https://github.com/paupino/rust-decimal/blob/master/BUILD.md)",
)
)?;
} else if feature_section && line.starts_with("```rust") {
// This is a bit naive, but it's to make the Serde examples cleaner. Should probably
// be a bit more "defensive" here.
} else if line.starts_with("```rust") {
writeln!(cleaned, "```rust")?;
writeln!(cleaned, "# use rust_decimal::Decimal;")?;
writeln!(cleaned, "# use serde::{{Serialize, Deserialize}};")?;
write!(cleaned, "# #[cfg(features = \"{feature}\")]")?;
writeln!(cleaned, "# use rust_decimal_macros::dec;")?;
if feature_section {
// This is a bit naive, but it's to make the Serde examples cleaner. Should probably
// be a bit more "defensive" here.
writeln!(cleaned, "# use serde::{{Serialize, Deserialize}};")?;
write!(cleaned, "# #[cfg(features = \"{feature}\")]")?;
}
} else {
if !feature_section && line.starts_with("## Features") {
feature_section = true;
3 changes: 3 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -14,3 +14,6 @@ cargo run
This example shows how to use the `serde` crate to serialize and deserialize the `Decimal` type using multiple different
serialization formats.

## rkyv-remote

This example shows shows how to use the `rkyv` crate's remote derive for the `Decimal` type.
35 changes: 35 additions & 0 deletions examples/rkyv-remote.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
extern crate rkyv_0_8 as rkyv;

use rkyv::{rancor::Error, Archive, Deserialize, Serialize};
use rust_decimal::prelude::{dec, Decimal};

/// The type containing a [`Decimal`] that will be de/serialized.
#[derive(Archive, Serialize, Deserialize, Debug, PartialEq, Eq)]
struct Root {
#[rkyv(with = RkyvDecimal)]
decimal: Decimal,
}

/// Archived layout of [`Decimal`]
#[derive(Archive, Serialize, Deserialize)]
#[rkyv(remote = Decimal)]
struct RkyvDecimal {
#[rkyv(getter = Decimal::serialize)]
bytes: [u8; 16],
}

impl From<RkyvDecimal> for Decimal {
fn from(RkyvDecimal { bytes }: RkyvDecimal) -> Self {
Self::deserialize(bytes)
}
}

fn main() {
let test_value = Root { decimal: dec!(123.456) };

let bytes = rkyv::to_bytes::<Error>(&test_value).expect("Failed to serialize");

let roundtrip_value = rkyv::from_bytes::<Root, Error>(&bytes).expect("Failed to deserialize");

assert_eq!(test_value, roundtrip_value);
}
2 changes: 0 additions & 2 deletions examples/serde-json-scenarios/Cargo.toml
Original file line number Diff line number Diff line change
@@ -4,8 +4,6 @@ version = "0.0.0"
edition = "2021"
publish = false

[workspace]

[dependencies]
rust_decimal = { path = "../..", features = ["serde-with-arbitrary-precision"] }
rust_decimal_macros = { path = "../../macros" }
1 change: 0 additions & 1 deletion examples/serde-json-scenarios/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use rust_decimal::prelude::*;
use rust_decimal_macros::dec;

type ExampleResult = Result<(), Box<dyn std::error::Error>>;

5 changes: 3 additions & 2 deletions macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rust_decimal_macros"
version = "1.36.0"
version = "1.37.0"
authors = ["Paul Mason <paul@form1.co.nz>"]
edition = "2021"
description = "Shorthand macros to assist creating Decimal types."
@@ -12,10 +12,11 @@ categories = ["science", "data-structures"]
license = "MIT"

[dependencies]
rust_decimal = { version = "1.33", default-features = false }
quote = "1.0"
syn = { version = "2.0", features = ["full"] }

[dev-dependencies]
rust_decimal = { path = "..", default-features = false }
trybuild = "1.0.55"

[features]
Loading