Skip to content

Commit f7bbcca

Browse files
Rename serde1 feature to serde. (#1477)
1 parent 2d5948d commit f7bbcca

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+146
-136
lines changed

.github/workflows/gh-pages.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
RUSTDOCFLAGS: --cfg doc_cfg
3131
# --all builds all crates, but with default features for other crates (okay in this case)
3232
run: |
33-
cargo doc --all --features nightly,serde1,getrandom,small_rng
33+
cargo doc --all --features nightly,serde,getrandom,small_rng
3434
cp utils/redirect.html target/doc/index.html
3535
rm target/doc/.lock
3636

.github/workflows/test.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,21 +95,21 @@ jobs:
9595
cargo test --target ${{ matrix.target }} --examples
9696
- name: Test rand (all stable features)
9797
run: |
98-
cargo test --target ${{ matrix.target }} --features=serde1,log,small_rng
98+
cargo test --target ${{ matrix.target }} --features=serde,log,small_rng
9999
- name: Test rand_core
100100
run: |
101101
cargo test --target ${{ matrix.target }} --manifest-path rand_core/Cargo.toml
102102
cargo test --target ${{ matrix.target }} --manifest-path rand_core/Cargo.toml --no-default-features
103103
cargo test --target ${{ matrix.target }} --manifest-path rand_core/Cargo.toml --no-default-features --features=alloc,getrandom
104104
- name: Test rand_distr
105105
run: |
106-
cargo test --target ${{ matrix.target }} --manifest-path rand_distr/Cargo.toml --features=serde1
106+
cargo test --target ${{ matrix.target }} --manifest-path rand_distr/Cargo.toml --features=serde
107107
cargo test --target ${{ matrix.target }} --manifest-path rand_distr/Cargo.toml --no-default-features
108108
cargo test --target ${{ matrix.target }} --manifest-path rand_distr/Cargo.toml --no-default-features --features=std,std_math
109109
- name: Test rand_pcg
110-
run: cargo test --target ${{ matrix.target }} --manifest-path rand_pcg/Cargo.toml --features=serde1
110+
run: cargo test --target ${{ matrix.target }} --manifest-path rand_pcg/Cargo.toml --features=serde
111111
- name: Test rand_chacha
112-
run: cargo test --target ${{ matrix.target }} --manifest-path rand_chacha/Cargo.toml --features=serde1
112+
run: cargo test --target ${{ matrix.target }} --manifest-path rand_chacha/Cargo.toml --features=serde
113113

114114
test-cross:
115115
runs-on: ${{ matrix.os }}
@@ -138,11 +138,11 @@ jobs:
138138
- name: Test
139139
run: |
140140
# all stable features:
141-
cross test --no-fail-fast --target ${{ matrix.target }} --features=serde1,log,small_rng
141+
cross test --no-fail-fast --target ${{ matrix.target }} --features=serde,log,small_rng
142142
cross test --no-fail-fast --target ${{ matrix.target }} --examples
143143
cross test --no-fail-fast --target ${{ matrix.target }} --manifest-path rand_core/Cargo.toml
144-
cross test --no-fail-fast --target ${{ matrix.target }} --manifest-path rand_distr/Cargo.toml --features=serde1
145-
cross test --no-fail-fast --target ${{ matrix.target }} --manifest-path rand_pcg/Cargo.toml --features=serde1
144+
cross test --no-fail-fast --target ${{ matrix.target }} --manifest-path rand_distr/Cargo.toml --features=serde
145+
cross test --no-fail-fast --target ${{ matrix.target }} --manifest-path rand_pcg/Cargo.toml --features=serde
146146
cross test --no-fail-fast --target ${{ matrix.target }} --manifest-path rand_chacha/Cargo.toml
147147
148148
test-miri:
@@ -159,10 +159,10 @@ jobs:
159159
cargo miri test --no-default-features --lib --tests
160160
cargo miri test --features=log,small_rng
161161
cargo miri test --manifest-path rand_core/Cargo.toml
162-
cargo miri test --manifest-path rand_core/Cargo.toml --features=serde1
162+
cargo miri test --manifest-path rand_core/Cargo.toml --features=serde
163163
cargo miri test --manifest-path rand_core/Cargo.toml --no-default-features
164164
#cargo miri test --manifest-path rand_distr/Cargo.toml # no unsafe and lots of slow tests
165-
cargo miri test --manifest-path rand_pcg/Cargo.toml --features=serde1
165+
cargo miri test --manifest-path rand_pcg/Cargo.toml --features=serde
166166
cargo miri test --manifest-path rand_chacha/Cargo.toml --no-default-features
167167
168168
test-no-std:

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ You may also find the [Upgrade Guide](https://rust-random.github.io/book/update.
1919
- Allow `UniformFloat::new` samples and `UniformFloat::sample_single` to yield `high` (#1462)
2020
- Fix portability of `rand::distributions::Slice` (#1469)
2121
- Rename `rand::distributions` to `rand::distr` (#1470)
22+
- The `serde1` feature has been renamed `serde` (#1477)
2223

2324
## [0.9.0-alpha.1] - 2024-03-18
2425
- Add the `Slice::num_choices` method to the Slice distribution (#1402)

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ all-features = true
2424
rustdoc-args = ["--cfg", "docsrs", "--generate-link-to-definition"]
2525

2626
[package.metadata.playground]
27-
features = ["small_rng", "serde1"]
27+
features = ["small_rng", "serde"]
2828

2929
[features]
3030
# Meta-features:
3131
default = ["std", "std_rng", "getrandom", "small_rng"]
3232
nightly = [] # some additions requiring nightly Rust
33-
serde1 = ["serde", "rand_core/serde1"]
33+
serde = ["dep:serde", "rand_core/serde"]
3434

3535
# Option (enabled by default): without "std" rand uses libcore; this option
3636
# enables functionality expected to be available on a standard platform.
@@ -74,6 +74,6 @@ zerocopy = { version = "0.7.33", default-features = false, features = ["simd"] }
7474

7575
[dev-dependencies]
7676
rand_pcg = { path = "rand_pcg", version = "=0.9.0-alpha.1" }
77-
# Only to test serde1
77+
# Only to test serde
7878
bincode = "1.2.1"
7979
rayon = "1.7"

rand_chacha/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [Unreleased]
8+
- The `serde1` feature has been renamed `serde` (#1477)
9+
710
## [0.9.0-alpha.1] - 2024-03-18
811

912
## [0.9.0-alpha.0] - 2024-02-18

rand_chacha/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ ppv-lite86 = { version = "0.2.14", default-features = false, features = ["simd"]
2525
serde = { version = "1.0", features = ["derive"], optional = true }
2626

2727
[dev-dependencies]
28-
# Only to test serde1
28+
# Only to test serde
2929
serde_json = "1.0"
3030
rand_core = { path = "../rand_core", version = "=0.9.0-alpha.1", features = ["getrandom"] }
3131

3232
[features]
3333
default = ["std"]
3434
getrandom = ["rand_core/getrandom"]
3535
std = ["ppv-lite86/std", "rand_core/std"]
36-
serde1 = ["serde"]
36+
serde = ["dep:serde"]

rand_chacha/src/chacha.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crate::guts::ChaCha;
1818
use rand_core::block::{BlockRng, BlockRngCore, CryptoBlockRng};
1919
use rand_core::{CryptoRng, RngCore, SeedableRng};
2020

21-
#[cfg(feature = "serde1")]
21+
#[cfg(feature = "serde")]
2222
use serde::{Deserialize, Deserializer, Serialize, Serializer};
2323

2424
// NB. this must remain consistent with some currently hard-coded numbers in this module
@@ -276,7 +276,7 @@ macro_rules! chacha_impl {
276276
}
277277
impl Eq for $ChaChaXRng {}
278278

279-
#[cfg(feature = "serde1")]
279+
#[cfg(feature = "serde")]
280280
impl Serialize for $ChaChaXRng {
281281
fn serialize<S>(&self, s: S) -> Result<S::Ok, S::Error>
282282
where
@@ -285,7 +285,7 @@ macro_rules! chacha_impl {
285285
$abst::$ChaChaXRng::from(self).serialize(s)
286286
}
287287
}
288-
#[cfg(feature = "serde1")]
288+
#[cfg(feature = "serde")]
289289
impl<'de> Deserialize<'de> for $ChaChaXRng {
290290
fn deserialize<D>(d: D) -> Result<Self, D::Error>
291291
where
@@ -296,14 +296,14 @@ macro_rules! chacha_impl {
296296
}
297297

298298
mod $abst {
299-
#[cfg(feature = "serde1")]
299+
#[cfg(feature = "serde")]
300300
use serde::{Deserialize, Serialize};
301301

302302
// The abstract state of a ChaCha stream, independent of implementation choices. The
303303
// comparison and serialization of this object is considered a semver-covered part of
304304
// the API.
305305
#[derive(Debug, PartialEq, Eq)]
306-
#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
306+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
307307
pub(crate) struct $ChaChaXRng {
308308
seed: [u8; 32],
309309
stream: u64,
@@ -362,12 +362,12 @@ chacha_impl!(
362362
mod test {
363363
use rand_core::{RngCore, SeedableRng};
364364

365-
#[cfg(feature = "serde1")]
365+
#[cfg(feature = "serde")]
366366
use super::{ChaCha12Rng, ChaCha20Rng, ChaCha8Rng};
367367

368368
type ChaChaRng = super::ChaCha20Rng;
369369

370-
#[cfg(feature = "serde1")]
370+
#[cfg(feature = "serde")]
371371
#[test]
372372
fn test_chacha_serde_roundtrip() {
373373
let seed = [
@@ -405,7 +405,7 @@ mod test {
405405
// However testing for equivalence of serialized data is difficult, and there shouldn't be any
406406
// reason we need to violate the stronger-than-needed condition, e.g. by changing the field
407407
// definition order.
408-
#[cfg(feature = "serde1")]
408+
#[cfg(feature = "serde")]
409409
#[test]
410410
fn test_chacha_serde_format_stability() {
411411
let j = r#"{"seed":[4,8,15,16,23,42,4,8,15,16,23,42,4,8,15,16,23,42,4,8,15,16,23,42,4,8,15,16,23,42,4,8],"stream":27182818284,"word_pos":314159265359}"#;

rand_core/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88
- Bump the MSRV to 1.61.0
9+
- The `serde1` feature has been renamed `serde` (#1477)
910

1011
## [0.9.0-alpha.1] - 2024-03-18
1112

rand_core/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ all-features = true
2727
[features]
2828
std = ["alloc", "getrandom?/std"]
2929
alloc = [] # enables Vec and Box support without std
30-
serde1 = ["serde"] # enables serde for BlockRng wrapper
30+
serde = ["dep:serde"] # enables serde for BlockRng wrapper
3131

3232
[dependencies]
3333
serde = { version = "1", features = ["derive"], optional = true }

rand_core/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ problems where one crate implicitly requires `rand_core` with `std` support and
6767
another crate requires `rand` *without* `std` support. However, the `rand` crate
6868
continues to enable `std` support by default, both for itself and `rand_core`.
6969

70-
The `serde1` feature can be used to derive `Serialize` and `Deserialize` for RNG
70+
The `serde` feature can be used to derive `Serialize` and `Deserialize` for RNG
7171
implementations that use the `BlockRng` or `BlockRng64` wrappers.
7272

7373

rand_core/src/block.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
use crate::impls::{fill_via_u32_chunks, fill_via_u64_chunks};
5757
use crate::{CryptoRng, RngCore, SeedableRng, TryRngCore};
5858
use core::fmt;
59-
#[cfg(feature = "serde1")]
59+
#[cfg(feature = "serde")]
6060
use serde::{Deserialize, Serialize};
6161

6262
/// A trait for RNGs which do not generate random numbers individually, but in
@@ -116,9 +116,9 @@ pub trait CryptoBlockRng: BlockRngCore {}
116116
/// [`next_u64`]: RngCore::next_u64
117117
/// [`fill_bytes`]: RngCore::fill_bytes
118118
#[derive(Clone)]
119-
#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
119+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
120120
#[cfg_attr(
121-
feature = "serde1",
121+
feature = "serde",
122122
serde(
123123
bound = "for<'x> R: Serialize + Deserialize<'x> + Sized, for<'x> R::Results: Serialize + Deserialize<'x>"
124124
)
@@ -283,7 +283,7 @@ impl<R: CryptoBlockRng + BlockRngCore<Item = u32>> CryptoRng for BlockRng<R> {}
283283
/// [`next_u64`]: RngCore::next_u64
284284
/// [`fill_bytes`]: RngCore::fill_bytes
285285
#[derive(Clone)]
286-
#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
286+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
287287
pub struct BlockRng64<R: BlockRngCore + ?Sized> {
288288
results: R::Results,
289289
index: usize,

rand_distr/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## Unreleased
8+
- The `serde1` feature has been renamed `serde` (#1477)
9+
810
### Added
911
- Add plots for `rand_distr` distributions to documentation (#1434)
1012
- Add `PertBuilder`, fix case where mode ≅ mean (#1452)

rand_distr/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ alloc = ["rand/alloc"]
2929
# feature (default-enabled) will have the same effect.
3030
std_math = ["num-traits/std"]
3131

32-
serde1 = ["serde", "rand/serde1"]
32+
serde = ["dep:serde", "rand/serde"]
3333

3434
[dependencies]
3535
rand = { path = "..", version = "=0.9.0-alpha.1", default-features = false }

rand_distr/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ can be enabled. (Note that any other crate depending on `num-traits` with the
3535
- `alloc` (enabled by default): required for some distributions when not using
3636
`std` (in particular, `Dirichlet` and `WeightedAliasIndex`).
3737
- `std_math`: see above on portability and libm
38-
- `serde1`: implement (de)seriaialization using `serde`
38+
- `serde`: implement (de)seriaialization using `serde`
3939

4040
## Links
4141

rand_distr/src/beta.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::{Distribution, Open01};
1313
use core::fmt;
1414
use num_traits::Float;
1515
use rand::Rng;
16-
#[cfg(feature = "serde1")]
16+
#[cfg(feature = "serde")]
1717
use serde::{Deserialize, Serialize};
1818

1919
/// The algorithm used for sampling the Beta distribution.
@@ -25,15 +25,15 @@ use serde::{Deserialize, Serialize};
2525
/// Communications of the ACM 21, 317-322.
2626
/// https://doi.org/10.1145/359460.359482
2727
#[derive(Clone, Copy, Debug, PartialEq)]
28-
#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
28+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2929
enum BetaAlgorithm<N> {
3030
BB(BB<N>),
3131
BC(BC<N>),
3232
}
3333

3434
/// Algorithm BB for `min(alpha, beta) > 1`.
3535
#[derive(Clone, Copy, Debug, PartialEq)]
36-
#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
36+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
3737
struct BB<N> {
3838
alpha: N,
3939
beta: N,
@@ -42,7 +42,7 @@ struct BB<N> {
4242

4343
/// Algorithm BC for `min(alpha, beta) <= 1`.
4444
#[derive(Clone, Copy, Debug, PartialEq)]
45-
#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
45+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
4646
struct BC<N> {
4747
alpha: N,
4848
beta: N,
@@ -77,7 +77,7 @@ struct BC<N> {
7777
/// println!("{} is from a Beta(2, 5) distribution", v);
7878
/// ```
7979
#[derive(Clone, Copy, Debug, PartialEq)]
80-
#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
80+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8181
pub struct Beta<F>
8282
where
8383
F: Float,
@@ -91,7 +91,7 @@ where
9191

9292
/// Error type returned from [`Beta::new`].
9393
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
94-
#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
94+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9595
pub enum Error {
9696
/// `alpha <= 0` or `nan`.
9797
AlphaTooSmall,

rand_distr/src/binomial.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ use rand::Rng;
4444
/// println!("{} is from a binomial distribution", v);
4545
/// ```
4646
#[derive(Clone, Copy, Debug, PartialEq)]
47-
#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
47+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
4848
pub struct Binomial {
4949
/// Number of trials.
5050
n: u64,

rand_distr/src/cauchy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ use rand::Rng;
5454
/// Note that at least for `f32`, results are not fully portable due to minor
5555
/// differences in the target system's *tan* implementation, `tanf`.
5656
#[derive(Clone, Copy, Debug, PartialEq)]
57-
#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
57+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
5858
pub struct Cauchy<F>
5959
where
6060
F: Float + FloatConst,

rand_distr/src/chi_squared.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::{Distribution, Exp1, Gamma, Open01, StandardNormal};
1515
use core::fmt;
1616
use num_traits::Float;
1717
use rand::Rng;
18-
#[cfg(feature = "serde1")]
18+
#[cfg(feature = "serde")]
1919
use serde::{Deserialize, Serialize};
2020

2121
/// The [chi-squared distribution](https://en.wikipedia.org/wiki/Chi-squared_distribution) `χ²(k)`.
@@ -45,7 +45,7 @@ use serde::{Deserialize, Serialize};
4545
/// println!("{} is from a χ²(11) distribution", v)
4646
/// ```
4747
#[derive(Clone, Copy, Debug, PartialEq)]
48-
#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
48+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
4949
pub struct ChiSquared<F>
5050
where
5151
F: Float,
@@ -58,7 +58,7 @@ where
5858

5959
/// Error type returned from [`ChiSquared::new`] and [`StudentT::new`](crate::StudentT::new).
6060
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
61-
#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
61+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6262
pub enum Error {
6363
/// `0.5 * k <= 0` or `nan`.
6464
DoFTooSmall,
@@ -78,7 +78,7 @@ impl fmt::Display for Error {
7878
impl std::error::Error for Error {}
7979

8080
#[derive(Clone, Copy, Debug, PartialEq)]
81-
#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
81+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8282
enum ChiSquaredRepr<F>
8383
where
8484
F: Float,

rand_distr/src/dirichlet.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ where
9292
}
9393

9494
#[derive(Clone, Debug, PartialEq)]
95-
#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
95+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
9696
struct DirichletFromBeta<F, const N: usize>
9797
where
9898
F: Float,

0 commit comments

Comments
 (0)