Skip to content

Commit d7662ef

Browse files
author
Tony Samuels
committed
chore: standardise dependencies
1 parent 3eaaa64 commit d7662ef

File tree

10 files changed

+53
-85
lines changed

10 files changed

+53
-85
lines changed

CONTRIBUTING.md

+14
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,20 @@ Should you wish to work on an issue, please claim it first by commenting on
1515
the GitHub issue that you want to work on it. This is to prevent duplicated
1616
efforts from contributors on the same issue.
1717

18+
## Adding new dependencies
19+
20+
### Pre-1.0 releases
21+
22+
When adding a new 0.X release, in order to avoid ambiguity as the dependency adds new versions, ensure the version is included in the feature name. e.g.
23+
24+
```toml
25+
[dependencies]
26+
rand-0_9 = { default-features = false, optional = true, package = "rand", version = "0.9" }
27+
28+
[features]
29+
rand-0_9 = ["dep:rand-0_9"]
30+
```
31+
1832
## Pull Request Checklist
1933

2034
- Branch from the master branch and, if needed, rebase to the current master

Cargo.toml

+22-24
Original file line numberDiff line numberDiff line change
@@ -19,39 +19,39 @@ all-features = true
1919
rustdoc-args = ["--cfg", "docsrs"]
2020

2121
[dependencies]
22-
arbitrary = { default-features = false, optional = true, version = "1.0" }
22+
arbitrary = { default-features = false, optional = true, version = "1" }
2323
arrayvec = { default-features = false, version = "0.7" }
24-
borsh = { default-features = false, features = ["derive", "unstable__schema"], optional = true, version = "1.1.1" }
25-
bytes = { default-features = false, optional = true, version = "1.0" }
26-
diesel = { default-features = false, optional = true, version = "2.2.3" }
27-
ndarray = { default-features = false, optional = true, version = "0.15.6" }
28-
num-traits = { default-features = false, features = ["i128"], version = "0.2" }
29-
postgres-types = { default-features = false, optional = true, version = "0.2" }
24+
borsh = { default-features = false, features = ["derive", "unstable__schema"], optional = true, version = "1" }
25+
bytes = { default-features = false, optional = true, version = "1" }
26+
diesel = { default-features = false, optional = true, version = "2" }
27+
ndarray-0_16 = { default-features = false, optional = true, package = "ndarray", version = "0.16" }
28+
num-traits = { default-features = false, features = ["i128"], package = "num-traits", version = "0.2" }
29+
postgres-types = { default-features = false, optional = true, package = "postgres-types", version = "0.2" }
3030
proptest = { default-features = false, optional = true, features = ["std"], version = "1.0" }
3131
rand-0_9 = { default-features = false, optional = true, package = "rand", version = "0.9" }
32+
rocket = { default-features = false, optional = true, version = "0.5" }
3233
rust_decimal_macros = { path = "macros", default-features = false, optional = true, version = "1" }
33-
rkyv = { default-features = false, features = ["size_32", "std"], optional = true, version = "0.7.42" }
34-
rocket = { default-features = false, optional = true, version = "0.5.0-rc.3" }
35-
serde = { default-features = false, optional = true, version = "1.0" }
36-
serde_json = { default-features = false, optional = true, version = "1.0" }
37-
tokio-postgres = { default-features = false, optional = true, version = "0.7" }
34+
serde = { default-features = false, optional = true, version = "1" }
35+
serde_json = { default-features = false, optional = true, version = "1" }
3836

3937
[dev-dependencies]
40-
bincode = { default-features = false, version = "1.0" }
41-
bytes = { default-features = false, version = "1.0" }
38+
bincode = { default-features = false, version = "1" }
39+
bytes = { default-features = false, version = "1" }
4240
criterion = { default-features = false, version = "0.5" }
4341
csv = "1"
44-
diesel = { default-features = false, features = ["mysql"], version = "2.2.3" }
42+
diesel = { default-features = false, features = ["mysql"], version = "2" }
4543
futures = { default-features = false, version = "0.3" }
44+
postgres = { default-features = false, version = "0.19" }
4645
rand-0_9 = { default-features = false, features = ["thread_rng"], package = "rand", version = "0.9" }
4746
rkyv-0_8 = { version = "0.8", package = "rkyv" }
48-
rust_decimal_macros = { path = "macros" }
4947
serde = { default-features = false, features = ["derive"], version = "1.0" }
5048
serde_json = "1.0"
51-
tokio = { default-features = false, features = ["macros", "rt-multi-thread", "test-util"], version = "1.0" }
52-
version-sync = { default-features = false, features = ["html_root_url_updated", "markdown_deps_updated"], version = "0.9" }
53-
postgres = { default-features = false, version = "0.19" }
49+
tokio = { default-features = false, features = ["macros", "rt-multi-thread", "test-util"], version = "1" }
5450
tokio-postgres = { default-features = false, version = "0.7" }
51+
version-sync = { default-features = false, features = ["html_root_url_updated", "markdown_deps_updated"], version = "0.9" }
52+
53+
# Enable features for testing
54+
rust_decimal = { path = ".", features = ["rand-0_9", "macros", "rocket-0_5-traits"] }
5555

5656
[features]
5757
default = ["serde", "std"]
@@ -67,12 +67,10 @@ db-tokio-postgres = ["dep:bytes", "dep:postgres-types", "std"]
6767
macros = ["dep:rust_decimal_macros"]
6868
maths = []
6969
maths-nopanic = ["maths"]
70-
ndarray = ["dep:ndarray"]
70+
ndarray-0_16 = ["dep:ndarray-0_16"]
7171
proptest = ["dep:proptest"]
7272
rand-0_9 = ["dep:rand-0_9"]
73-
rkyv = ["dep:rkyv"]
74-
rkyv-safe = ["rkyv/validation"]
75-
rocket-traits = ["dep:rocket", "std"]
73+
rocket-0_5-traits = ["dep:rocket", "std"]
7674
rust-fuzz = ["dep:arbitrary"]
7775
serde = ["dep:serde"]
7876
serde-arbitrary-precision = ["serde-with-arbitrary-precision"]
@@ -82,7 +80,7 @@ serde-str = ["serde-with-str"]
8280
serde-with-arbitrary-precision = ["serde", "serde_json/arbitrary_precision", "serde_json/std"]
8381
serde-with-float = ["serde"]
8482
serde-with-str = ["serde"]
85-
std = ["arrayvec/std", "borsh?/std", "bytes?/std", "rand-0_9?/std", "rkyv?/std", "serde?/std", "serde_json?/std"]
83+
std = ["arrayvec/std", "borsh?/std", "bytes?/std", "rand-0_9?/std", "serde?/std", "serde_json?/std"]
8684
tokio-pg = ["db-tokio-postgres"] # Backwards compatability
8785

8886
[[bench]]

benches/lib_benches.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ fn decimal_to_string(b: &mut test::Bencher) {
210210
})
211211
}
212212

213-
#[cfg(feature = "postgres")]
213+
#[cfg(feature = "db-postgres")]
214214
#[bench]
215215
fn to_from_sql(b: &mut ::test::Bencher) {
216216
use bytes::BytesMut;

make/tests/misc.toml

+2-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ dependencies = [
44
"test-rust-fuzz",
55
"test-rocket-traits",
66
"test-borsh",
7-
"test-rkyv",
87
"test-rand"
98
]
109

@@ -18,19 +17,15 @@ args = ["test", "--workspace", "--no-default-features", "--features=rust-fuzz",
1817

1918
[tasks.test-rocket-traits]
2019
command = "cargo"
21-
args = ["test", "--workspace", "--features=rocket-traits", "rocket_tests"]
20+
args = ["test", "--workspace", "--features=rocket-0_5-traits", "rocket_tests"]
2221

2322
[tasks.test-borsh]
2423
command = "cargo"
2524
args = ["test", "--workspace", "--features=borsh", "borsh_tests", "--", "--skip", "generated"]
2625

2726
[tasks.test-ndarray]
2827
command = "cargo"
29-
args = ["test", "--workspace", "--features=ndarray", "nd_array_tests", "--", "--skip", "generated"]
30-
31-
[tasks.test-rkyv]
32-
command = "cargo"
33-
args = ["test", "--workspace", "--features=rkyv", "--features=rkyv-safe", "rkyv_tests", "--", "--skip", "generated"]
28+
args = ["test", "--workspace", "--features=ndarray-0_16", "nd_array_tests", "--", "--skip", "generated"]
3429

3530
[tasks.test-rand]
3631
dependencies = [

src/decimal.rs

+2-11
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ use diesel::{deserialize::FromSqlRow, expression::AsExpression, sql_types::Numer
2121
#[cfg(not(feature = "std"))]
2222
use num_traits::float::FloatCore;
2323
use num_traits::{FromPrimitive, Num, One, Signed, ToPrimitive, Zero};
24-
#[cfg(feature = "rkyv")]
25-
use rkyv::{Archive, Deserialize, Serialize};
2624

2725
/// The smallest value that can be represented by this decimal type.
2826
const MIN: Decimal = Decimal {
@@ -105,13 +103,6 @@ pub struct UnpackedDecimal {
105103
feature = "borsh",
106104
derive(borsh::BorshDeserialize, borsh::BorshSerialize, borsh::BorshSchema)
107105
)]
108-
#[cfg_attr(
109-
feature = "rkyv",
110-
derive(Archive, Deserialize, Serialize),
111-
archive(compare(PartialEq)),
112-
archive_attr(derive(Clone, Copy, Debug))
113-
)]
114-
#[cfg_attr(feature = "rkyv-safe", archive(check_bytes))]
115106
pub struct Decimal {
116107
// Bits 0-15: unused
117108
// Bits 16-23: Contains "e", a value between 0-28 that indicates the scale
@@ -125,8 +116,8 @@ pub struct Decimal {
125116
mid: u32,
126117
}
127118

128-
#[cfg(feature = "ndarray")]
129-
impl ndarray::ScalarOperand for Decimal {}
119+
#[cfg(feature = "ndarray-0_16")]
120+
impl ndarray_0_16::ScalarOperand for Decimal {}
130121

131122
/// `RoundingStrategy` represents the different rounding strategies that can be used by
132123
/// `round_dp_with_strategy`.

src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ mod postgres;
3030
mod proptest;
3131
#[cfg(feature = "rand-0_9")]
3232
mod rand_0_9;
33-
#[cfg(feature = "rocket-traits")]
34-
mod rocket;
33+
#[cfg(feature = "rocket-0_5-traits")]
34+
mod rocket_0_5;
3535
#[cfg(all(
3636
feature = "serde",
3737
not(any(

src/rand_0_9.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ fn sync_scales(mut a: Decimal, mut b: Decimal) -> (Decimal, Decimal) {
128128

129129
#[cfg(test)]
130130
mod rand_tests {
131+
use rand_0_9::rng;
131132
use std::collections::HashSet;
132133

133134
use super::*;
@@ -140,14 +141,14 @@ mod rand_tests {
140141

141142
#[test]
142143
fn has_random_decimal_instances() {
143-
let mut rng = rand_0_9::rng();
144+
let mut rng = rng();
144145
let random: [Decimal; 32] = rng.random();
145146
assert!(random.windows(2).any(|slice| { slice[0] != slice[1] }));
146147
}
147148

148149
#[test]
149150
fn generates_within_range() {
150-
let mut rng = rand_0_9::rng();
151+
let mut rng = rng();
151152
for _ in 0..128 {
152153
let random = rng.random_range(dec!(1.00)..dec!(1.05));
153154
assert!(random < dec!(1.05));
@@ -157,7 +158,7 @@ mod rand_tests {
157158

158159
#[test]
159160
fn generates_within_inclusive_range() {
160-
let mut rng = rand_0_9::rng();
161+
let mut rng = rng();
161162
let mut values: HashSet<Decimal> = HashSet::new();
162163
for _ in 0..256 {
163164
let random = rng.random_range(dec!(1.00)..=dec!(1.01));
File renamed without changes.

src/serde.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -592,9 +592,10 @@ mod test {
592592
#[test]
593593
#[cfg(feature = "serde-arbitrary-precision")]
594594
fn deserialize_basic_decimal() {
595-
let d: Decimal = serde_json::from_str("1.1234127836128763").unwrap();
595+
let s = "1.1234127836128763";
596+
let d: Decimal = serde_json::from_str(s).unwrap();
596597
// Typically, this would not work without this feature enabled due to rounding
597-
assert_eq!(d.to_string(), "1.1234127836128763");
598+
assert_eq!(d.to_string(), s);
598599
}
599600

600601
#[test]

tests/decimal_tests.rs

+3-35
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,13 @@ mod borsh_tests {
157157
}
158158
}
159159

160-
#[cfg(feature = "ndarray")]
160+
#[cfg(feature = "ndarray-0_16")]
161161
mod ndarray_tests {
162162
use rust_decimal::Decimal;
163163

164164
#[test]
165165
fn it_can_do_scalar_ops_in_ndarray() {
166-
use ndarray::Array1;
166+
use ndarray_0_16::Array1;
167167
use num_traits::FromPrimitive;
168168

169169
let array_a = Array1::from(vec![
@@ -210,38 +210,6 @@ mod ndarray_tests {
210210
}
211211
}
212212

213-
#[cfg(feature = "rkyv")]
214-
mod rkyv_tests {
215-
use rust_decimal::Decimal;
216-
use std::str::FromStr;
217-
218-
#[test]
219-
fn it_can_serialize_deserialize_rkyv() {
220-
use rkyv::Deserialize;
221-
let tests = [
222-
"12.3456789",
223-
"5233.9008808150288439427720175",
224-
"-5233.9008808150288439427720175",
225-
];
226-
for test in &tests {
227-
let a = Decimal::from_str(test).unwrap();
228-
let bytes = rkyv::to_bytes::<_, 256>(&a).unwrap();
229-
230-
#[cfg(feature = "rkyv-safe")]
231-
{
232-
let archived = rkyv::check_archived_root::<Decimal>(&bytes[..]).unwrap();
233-
assert_eq!(archived, &a);
234-
}
235-
236-
let archived = unsafe { rkyv::archived_root::<Decimal>(&bytes[..]) };
237-
assert_eq!(archived, &a);
238-
239-
let deserialized: Decimal = archived.deserialize(&mut rkyv::Infallible).unwrap();
240-
assert_eq!(deserialized, a);
241-
}
242-
}
243-
}
244-
245213
#[test]
246214
fn it_can_deserialize_unbounded_values() {
247215
// Mantissa for these: 19393111376951473493673267553
@@ -4656,7 +4624,7 @@ mod proptest_tests {
46564624
}
46574625
}
46584626

4659-
#[cfg(feature = "rocket-traits")]
4627+
#[cfg(feature = "rocket-0_5-traits")]
46604628
#[allow(clippy::disallowed_names)]
46614629
mod rocket_tests {
46624630
use crate::Decimal;

0 commit comments

Comments
 (0)