Skip to content

Commit 11c3663

Browse files
authored
Deprecate diesel1 feature and upgrade diesel to v2.2 (paupino#663)
1 parent b2d00c1 commit 11c3663

File tree

8 files changed

+120
-225
lines changed

8 files changed

+120
-225
lines changed

Cargo.toml

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
[package]
22
authors = ["Paul Mason <paul@form1.co.nz>"]
33
build = "build.rs"
4-
categories = ["science","mathematics","data-structures"]
4+
categories = ["science", "mathematics", "data-structures"]
55
description = "Decimal number implementation written in pure Rust suitable for financial and fixed-precision calculations."
66
documentation = "https://docs.rs/rust_decimal/"
77
edition = "2021"
8-
exclude = [ "tests/generated/*" ]
9-
keywords = ["decimal","financial","fixed","precision","number"]
8+
exclude = ["tests/generated/*"]
9+
keywords = ["decimal", "financial", "fixed", "precision", "number"]
1010
license = "MIT"
1111
name = "rust_decimal"
1212
readme = "./README.md"
@@ -23,8 +23,7 @@ arbitrary = { default-features = false, optional = true, version = "1.0" }
2323
arrayvec = { default-features = false, version = "0.7" }
2424
borsh = { default-features = false, features = ["derive", "unstable__schema"], optional = true, version = "1.1.1" }
2525
bytes = { default-features = false, optional = true, version = "1.0" }
26-
diesel1 = { default-features = false, optional = true, package = "diesel", version = "1.0" }
27-
diesel2 = { default-features = false, optional = true, package = "diesel", version = "2.1" }
26+
diesel = { default-features = false, optional = true, version = "2.2" }
2827
ndarray = { default-features = false, optional = true, version = "0.15.6" }
2928
num-traits = { default-features = false, features = ["i128"], version = "0.2" }
3029
postgres-types = { default-features = false, optional = true, version = "0.2" }
@@ -59,12 +58,10 @@ default = ["serde", "std"]
5958

6059
borsh = ["dep:borsh", "std"]
6160
c-repr = [] # Force Decimal to be repr(C)
62-
db-diesel-mysql = ["db-diesel1-mysql"]
63-
db-diesel-postgres = ["db-diesel1-postgres"]
64-
db-diesel1-mysql = ["diesel1/mysql", "std"]
65-
db-diesel1-postgres = ["diesel1/postgres", "std"]
66-
db-diesel2-mysql = ["diesel2/mysql", "std"]
67-
db-diesel2-postgres = ["diesel2/postgres", "std"]
61+
db-diesel-mysql = ["diesel/mysql", "std"]
62+
db-diesel-postgres = ["diesel/postgres", "std"]
63+
db-diesel2-mysql = ["db-diesel-mysql"]
64+
db-diesel2-postgres = ["db-diesel-postgres"]
6865
db-postgres = ["dep:bytes", "dep:postgres-types", "std"]
6966
db-tokio-postgres = ["dep:bytes", "dep:postgres-types", "std"]
7067
legacy-ops = []

README.md

Lines changed: 81 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
# Decimal &emsp; [![Build Status]][actions] [![Latest Version]][crates.io] [![Docs Badge]][docs]
22

33
[Build Status]: https://img.shields.io/endpoint.svg?url=https%3A%2F%2Factions-badge.atrox.dev%2Fpaupino%2Frust-decimal%2Fbadge&label=build&logo=none
4+
45
[actions]: https://actions-badge.atrox.dev/paupino/rust-decimal/goto
6+
57
[Latest Version]: https://img.shields.io/crates/v/rust-decimal.svg
8+
69
[crates.io]: https://crates.io/crates/rust-decimal
10+
711
[Docs Badge]: https://docs.rs/rust_decimal/badge.svg
12+
813
[docs]: https://docs.rs/rust_decimal
914

10-
A Decimal number implementation written in pure Rust suitable for financial calculations that require significant integral and fractional digits with no round-off errors.
15+
A Decimal number implementation written in pure Rust suitable for financial calculations that require significant
16+
integral and fractional digits with no round-off errors.
1117

12-
The binary representation consists of a 96 bit integer number, a scaling factor used to specify the decimal fraction and a 1 bit sign. Because of this representation, trailing zeros are preserved and may be exposed when in string form. These can be truncated using the `normalize` or `round_dp` functions.
18+
The binary representation consists of a 96 bit integer number, a scaling factor used to specify the decimal fraction and
19+
a 1 bit sign. Because of this representation, trailing zeros are preserved and may be exposed when in string form. These
20+
can be truncated using the `normalize` or `round_dp` functions.
1321

1422
## Installing
1523

@@ -33,7 +41,8 @@ rust_decimal_macros = "1.35"
3341

3442
## Usage
3543

36-
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:
44+
Decimal numbers can be created in a few distinct ways. The easiest and most efficient method of creating a Decimal is to
45+
use the procedural macro that can be enabled using the `macros` feature:
3746

3847
```rust
3948
// Import the `rust_decimal_macros` crate and use the macro directly from there.
@@ -44,7 +53,8 @@ assert_eq!(number, dec!(2.22));
4453
assert_eq!(number.to_string(), "2.22");
4554
```
4655

47-
Alternatively you can also use one of the Decimal number convenience functions ([see the docs](https://docs.rs/rust_decimal/) for more details):
56+
Alternatively you can also use one of the Decimal number convenience
57+
functions ([see the docs](https://docs.rs/rust_decimal/) for more details):
4858

4959
```rust
5060
// Using the prelude can help importing trait based functions (e.g. core::str::FromStr).
@@ -140,31 +150,30 @@ Enables the tokio postgres module allowing for async communication with PostgreS
140150

141151
### `db-diesel-postgres`
142152

143-
Enable `diesel` PostgreSQL support. By default, this enables version `1.4` of `diesel`. If you wish to use the `2.0`
144-
version of `diesel` then you can do so by using the feature `db-diesel2-postgres`. Please note, if both features are
145-
enabled then version 2 will supersede version 1.
153+
Enable [`diesel`](https://diesel.rs) PostgreSQL support.
146154

147155
### `db-diesel-mysql`
148156

149-
Enable `diesel` MySQL support. By default, this enables version `1.4` of `diesel`. If you wish to use the `2.0`
150-
version of `diesel` then you can do so by using the feature `db-diesel2-mysql`. Please note, if both features are
151-
enabled then version 2 will supersede version 1.
157+
Enable [`diesel`](https://diesel.rs) MySQL support.
152158

153159
### `legacy-ops`
154160

155161
**Warning:** This is deprecated and will be removed from a future versions.
156162

157-
As of `1.10` the algorithms used to perform basic operations have changed which has benefits of significant speed improvements.
163+
As of `1.10` the algorithms used to perform basic operations have changed which has benefits of significant speed
164+
improvements.
158165
To maintain backwards compatibility this can be opted out of by enabling the `legacy-ops` feature.
159166

160167
### `maths`
161168

162169
The `maths` feature enables additional complex mathematical functions such as `pow`, `ln`, `enf`, `exp` etc.
163170
Documentation detailing the additional functions can be found on the
164-
[`MathematicalOps`](https://docs.rs/rust_decimal/latest/rust_decimal/trait.MathematicalOps.html) trait.
171+
[`MathematicalOps`](https://docs.rs/rust_decimal/latest/rust_decimal/trait.MathematicalOps.html) trait.
165172

166-
Please note that `ln` and `log10` will panic on invalid input with `checked_ln` and `checked_log10` the preferred functions
167-
to curb against this. When the `maths` feature was first developed the library would instead return `0` on invalid input. To re-enable this
173+
Please note that `ln` and `log10` will panic on invalid input with `checked_ln` and `checked_log10` the preferred
174+
functions
175+
to curb against this. When the `maths` feature was first developed the library would instead return `0` on invalid
176+
input. To re-enable this
168177
non-panicking behavior, please use the feature: `maths-nopanic`.
169178

170179
### `ndarray`
@@ -179,10 +188,13 @@ Enables a [`proptest`](https://github.com/proptest-rs/proptest) strategy to gene
179188

180189
Implements `rand::distributions::Distribution<Decimal>` to allow the creation of random instances.
181190

182-
Note: When using `rand::Rng` trait to generate a decimal between a range of two other decimals, the scale of the randomly-generated
183-
decimal will be the same as the scale of the input decimals (or, if the inputs have different scales, the higher of the two).
191+
Note: When using `rand::Rng` trait to generate a decimal between a range of two other decimals, the scale of the
192+
randomly-generated
193+
decimal will be the same as the scale of the input decimals (or, if the inputs have different scales, the higher of the
194+
two).
184195

185196
### `rkyv`
197+
186198
Enables [rkyv](https://github.com/rkyv/rkyv) serialization for `Decimal`.
187199
Supports rkyv's safe API when the `rkyv-safe` feature is enabled as well.
188200

@@ -196,12 +208,14 @@ Enable `rust-fuzz` support by implementing the `Arbitrary` trait.
196208

197209
### `serde-float`
198210

199-
> **Note:** This feature applies float serialization/deserialization rules as the default method for handling `Decimal` numbers.
200-
See also the `serde-with-*` features for greater flexibility.
211+
> **Note:** This feature applies float serialization/deserialization rules as the default method for handling `Decimal`
212+
> numbers.
213+
> See also the `serde-with-*` features for greater flexibility.
201214
202215
Enable this so that JSON serialization of `Decimal` types are sent as a float instead of a string (default).
203216

204217
e.g. with this turned on, JSON serialization would output:
218+
205219
```json
206220
{
207221
"value": 1.234
@@ -210,8 +224,9 @@ e.g. with this turned on, JSON serialization would output:
210224

211225
### `serde-str`
212226

213-
> **Note:** This feature applies string serialization/deserialization rules as the default method for handling `Decimal` numbers.
214-
See also the `serde-with-*` features for greater flexibility.
227+
> **Note:** This feature applies string serialization/deserialization rules as the default method for handling `Decimal`
228+
> numbers.
229+
> See also the `serde-with-*` features for greater flexibility.
215230
216231
This is typically useful for `bincode` or `csv` like implementations.
217232

@@ -225,20 +240,23 @@ converting to `f64` _loses_ precision, it's highly recommended that you do NOT e
225240

226241
### `serde-arbitrary-precision`
227242

228-
> **Note:** This feature applies arbitrary serialization/deserialization rules as the default method for handling `Decimal` numbers.
229-
See also the `serde-with-*` features for greater flexibility.
243+
> **Note:** This feature applies arbitrary serialization/deserialization rules as the default method for
244+
> handling `Decimal` numbers.
245+
> See also the `serde-with-*` features for greater flexibility.
230246
231247
This is used primarily with `serde_json` and consequently adds it as a "weak dependency". This supports the
232248
`arbitrary_precision` feature inside `serde_json` when parsing decimals.
233249

234250
This is recommended when parsing "float" looking data as it will prevent data loss.
235251

236-
Please note, this currently serializes numbers in a float like format by default, which can be an unexpected consequence. For greater
252+
Please note, this currently serializes numbers in a float like format by default, which can be an unexpected
253+
consequence. For greater
237254
control over the serialization format, please use the `serde-with-arbitrary-precision` feature.
238255

239256
### `serde-with-float`
240257

241-
Enable this to access the module for serializing `Decimal` types to a float. This can be used in `struct` definitions like so:
258+
Enable this to access the module for serializing `Decimal` types to a float. This can be used in `struct` definitions
259+
like so:
242260

243261
```rust
244262
#[derive(Serialize, Deserialize)]
@@ -247,6 +265,7 @@ pub struct FloatExample {
247265
value: Decimal,
248266
}
249267
```
268+
250269
```rust
251270
#[derive(Serialize, Deserialize)]
252271
pub struct OptionFloatExample {
@@ -256,6 +275,7 @@ pub struct OptionFloatExample {
256275
```
257276

258277
Alternatively, if only the serialization feature is desired (e.g. to keep flexibility while deserialization):
278+
259279
```rust
260280
#[derive(Serialize, Deserialize)]
261281
pub struct FloatExample {
@@ -266,7 +286,8 @@ pub struct FloatExample {
266286

267287
### `serde-with-str`
268288

269-
Enable this to access the module for serializing `Decimal` types to a `String`. This can be used in `struct` definitions like so:
289+
Enable this to access the module for serializing `Decimal` types to a `String`. This can be used in `struct` definitions
290+
like so:
270291

271292
```rust
272293
#[derive(Serialize, Deserialize)]
@@ -275,6 +296,7 @@ pub struct StrExample {
275296
value: Decimal,
276297
}
277298
```
299+
278300
```rust
279301
#[derive(Serialize, Deserialize)]
280302
pub struct OptionStrExample {
@@ -283,8 +305,10 @@ pub struct OptionStrExample {
283305
}
284306
```
285307

286-
This feature isn't typically required for serialization however can be useful for deserialization purposes since it does not require
308+
This feature isn't typically required for serialization however can be useful for deserialization purposes since it does
309+
not require
287310
a type hint. Consequently, you can force this for just deserialization by:
311+
288312
```rust
289313
#[derive(Serialize, Deserialize)]
290314
pub struct StrExample {
@@ -295,7 +319,8 @@ pub struct StrExample {
295319

296320
### `serde-with-arbitrary-precision`
297321

298-
Enable this to access the module for deserializing `Decimal` types using the `serde_json/arbitrary_precision` feature. This can be used in `struct` definitions like so:
322+
Enable this to access the module for deserializing `Decimal` types using the `serde_json/arbitrary_precision` feature.
323+
This can be used in `struct` definitions like so:
299324

300325
```rust
301326
#[derive(Serialize, Deserialize)]
@@ -304,6 +329,7 @@ pub struct ArbitraryExample {
304329
value: Decimal,
305330
}
306331
```
332+
307333
```rust
308334
#[derive(Serialize, Deserialize)]
309335
pub struct OptionArbitraryExample {
@@ -312,8 +338,9 @@ pub struct OptionArbitraryExample {
312338
}
313339
```
314340

315-
An unexpected consequence of this feature is that it will serialize as a float like number. To prevent this, you can
341+
An unexpected consequence of this feature is that it will serialize as a float like number. To prevent this, you can
316342
target the struct to only deserialize with the `arbitrary_precision` feature:
343+
317344
```rust
318345
#[derive(Serialize, Deserialize)]
319346
pub struct ArbitraryExample {
@@ -328,7 +355,8 @@ Please see the `examples` directory for more information regarding `serde_json`
328355

329356
### `std`
330357

331-
Enable `std` library support. This is enabled by default, however in the future will be opt in. For now, to support `no_std`
358+
Enable `std` library support. This is enabled by default, however in the future will be opt in. For now, to
359+
support `no_std`
332360
libraries, this crate can be compiled with `--no-default-features`.
333361

334362
## Building
@@ -337,31 +365,41 @@ Please refer to the [Build document](BUILD.md) for more information on building
337365

338366
## Minimum Rust Compiler Version
339367

340-
The current _minimum_ compiler version is [`1.60.0`](https://github.com/rust-lang/rust/blob/master/RELEASES.md#version-1600-2022-04-07)
368+
The current _minimum_ compiler version
369+
is [`1.60.0`](https://github.com/rust-lang/rust/blob/master/RELEASES.md#version-1600-2022-04-07)
341370
which was released on `2022-04-07`.
342371

343-
This library maintains support for rust compiler versions that are 4 minor versions away from the current stable rust compiler version.
344-
For example, if the current stable compiler version is `1.50.0` then we will guarantee support up to and including `1.46.0`.
372+
This library maintains support for rust compiler versions that are 4 minor versions away from the current stable rust
373+
compiler version.
374+
For example, if the current stable compiler version is `1.50.0` then we will guarantee support up to and
375+
including `1.46.0`.
345376
Of note, we will only update the minimum supported version if and when required.
346377

347378
## Comparison to other Decimal implementations
348379

349-
During the development of this library, there were various design decisions made to ensure that decimal calculations would
350-
be quick, accurate and efficient. Some decisions, however, put limitations on what this library can do and ultimately what
351-
it is suitable for. One such decision was the structure of the internal decimal representation.
352-
353-
This library uses a mantissa of 96 bits made up of three 32-bit unsigned integers with a fourth 32-bit unsigned integer to represent the scale/sign
354-
(similar to the C and .NET Decimal implementations).
355-
This structure allows us to make use of algorithmic optimizations to implement basic arithmetic; ultimately this gives us the ability
356-
to squeeze out performance and make it one of the fastest implementations available. The downside of this approach however is that
380+
During the development of this library, there were various design decisions made to ensure that decimal calculations
381+
would
382+
be quick, accurate and efficient. Some decisions, however, put limitations on what this library can do and ultimately
383+
what
384+
it is suitable for. One such decision was the structure of the internal decimal representation.
385+
386+
This library uses a mantissa of 96 bits made up of three 32-bit unsigned integers with a fourth 32-bit unsigned integer
387+
to represent the scale/sign
388+
(similar to the C and .NET Decimal implementations).
389+
This structure allows us to make use of algorithmic optimizations to implement basic arithmetic; ultimately this gives
390+
us the ability
391+
to squeeze out performance and make it one of the fastest implementations available. The downside of this approach
392+
however is that
357393
the maximum number of significant digits that can be represented is roughly 28 base-10 digits (29 in some cases).
358394

359-
While this constraint is not an issue for many applications (e.g. when dealing with money), some applications may require a higher number of significant digits to be represented. Fortunately,
395+
While this constraint is not an issue for many applications (e.g. when dealing with money), some applications may
396+
require a higher number of significant digits to be represented. Fortunately,
360397
there are alternative implementations that may be worth investigating, such as:
361398

362399
* [bigdecimal](https://crates.io/crates/bigdecimal)
363400
* [decimal-rs](https://crates.io/crates/decimal-rs)
364401

365-
If you have further questions about the suitability of this library for your project, then feel free to either start a
366-
[discussion](https://github.com/paupino/rust-decimal/discussions) or open an [issue](https://github.com/paupino/rust-decimal/issues) and we'll
402+
If you have further questions about the suitability of this library for your project, then feel free to either start a
403+
[discussion](https://github.com/paupino/rust-decimal/discussions) or open
404+
an [issue](https://github.com/paupino/rust-decimal/issues) and we'll
367405
do our best to help.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy