Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename serde1 feature to serde. #1477

Merged
merged 1 commit into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/gh-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
RUSTDOCFLAGS: --cfg doc_cfg
# --all builds all crates, but with default features for other crates (okay in this case)
run: |
cargo doc --all --features nightly,serde1,getrandom,small_rng
cargo doc --all --features nightly,serde,getrandom,small_rng
cp utils/redirect.html target/doc/index.html
rm target/doc/.lock

Expand Down
18 changes: 9 additions & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,21 +95,21 @@ jobs:
cargo test --target ${{ matrix.target }} --examples
- name: Test rand (all stable features)
run: |
cargo test --target ${{ matrix.target }} --features=serde1,log,small_rng
cargo test --target ${{ matrix.target }} --features=serde,log,small_rng
- name: Test rand_core
run: |
cargo test --target ${{ matrix.target }} --manifest-path rand_core/Cargo.toml
cargo test --target ${{ matrix.target }} --manifest-path rand_core/Cargo.toml --no-default-features
cargo test --target ${{ matrix.target }} --manifest-path rand_core/Cargo.toml --no-default-features --features=alloc,getrandom
- name: Test rand_distr
run: |
cargo test --target ${{ matrix.target }} --manifest-path rand_distr/Cargo.toml --features=serde1
cargo test --target ${{ matrix.target }} --manifest-path rand_distr/Cargo.toml --features=serde
cargo test --target ${{ matrix.target }} --manifest-path rand_distr/Cargo.toml --no-default-features
cargo test --target ${{ matrix.target }} --manifest-path rand_distr/Cargo.toml --no-default-features --features=std,std_math
- name: Test rand_pcg
run: cargo test --target ${{ matrix.target }} --manifest-path rand_pcg/Cargo.toml --features=serde1
run: cargo test --target ${{ matrix.target }} --manifest-path rand_pcg/Cargo.toml --features=serde
- name: Test rand_chacha
run: cargo test --target ${{ matrix.target }} --manifest-path rand_chacha/Cargo.toml --features=serde1
run: cargo test --target ${{ matrix.target }} --manifest-path rand_chacha/Cargo.toml --features=serde

test-cross:
runs-on: ${{ matrix.os }}
Expand Down Expand Up @@ -138,11 +138,11 @@ jobs:
- name: Test
run: |
# all stable features:
cross test --no-fail-fast --target ${{ matrix.target }} --features=serde1,log,small_rng
cross test --no-fail-fast --target ${{ matrix.target }} --features=serde,log,small_rng
cross test --no-fail-fast --target ${{ matrix.target }} --examples
cross test --no-fail-fast --target ${{ matrix.target }} --manifest-path rand_core/Cargo.toml
cross test --no-fail-fast --target ${{ matrix.target }} --manifest-path rand_distr/Cargo.toml --features=serde1
cross test --no-fail-fast --target ${{ matrix.target }} --manifest-path rand_pcg/Cargo.toml --features=serde1
cross test --no-fail-fast --target ${{ matrix.target }} --manifest-path rand_distr/Cargo.toml --features=serde
cross test --no-fail-fast --target ${{ matrix.target }} --manifest-path rand_pcg/Cargo.toml --features=serde
cross test --no-fail-fast --target ${{ matrix.target }} --manifest-path rand_chacha/Cargo.toml

test-miri:
Expand All @@ -159,10 +159,10 @@ jobs:
cargo miri test --no-default-features --lib --tests
cargo miri test --features=log,small_rng
cargo miri test --manifest-path rand_core/Cargo.toml
cargo miri test --manifest-path rand_core/Cargo.toml --features=serde1
cargo miri test --manifest-path rand_core/Cargo.toml --features=serde
cargo miri test --manifest-path rand_core/Cargo.toml --no-default-features
#cargo miri test --manifest-path rand_distr/Cargo.toml # no unsafe and lots of slow tests
cargo miri test --manifest-path rand_pcg/Cargo.toml --features=serde1
cargo miri test --manifest-path rand_pcg/Cargo.toml --features=serde
cargo miri test --manifest-path rand_chacha/Cargo.toml --no-default-features

test-no-std:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ You may also find the [Upgrade Guide](https://rust-random.github.io/book/update.
- Allow `UniformFloat::new` samples and `UniformFloat::sample_single` to yield `high` (#1462)
- Fix portability of `rand::distributions::Slice` (#1469)
- Rename `rand::distributions` to `rand::distr` (#1470)
- The `serde1` feature has been renamed `serde` (#1477)

## [0.9.0-alpha.1] - 2024-03-18
- Add the `Slice::num_choices` method to the Slice distribution (#1402)
Expand Down
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ all-features = true
rustdoc-args = ["--cfg", "docsrs", "--generate-link-to-definition"]

[package.metadata.playground]
features = ["small_rng", "serde1"]
features = ["small_rng", "serde"]

[features]
# Meta-features:
default = ["std", "std_rng", "getrandom", "small_rng"]
nightly = [] # some additions requiring nightly Rust
serde1 = ["serde", "rand_core/serde1"]
serde = ["dep:serde", "rand_core/serde"]

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

[dev-dependencies]
rand_pcg = { path = "rand_pcg", version = "=0.9.0-alpha.1" }
# Only to test serde1
# Only to test serde
bincode = "1.2.1"
rayon = "1.7"
3 changes: 3 additions & 0 deletions rand_chacha/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
- The `serde1` feature has been renamed `serde` (#1477)

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

## [0.9.0-alpha.0] - 2024-02-18
Expand Down
4 changes: 2 additions & 2 deletions rand_chacha/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ ppv-lite86 = { version = "0.2.14", default-features = false, features = ["simd"]
serde = { version = "1.0", features = ["derive"], optional = true }

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

[features]
default = ["std"]
getrandom = ["rand_core/getrandom"]
std = ["ppv-lite86/std", "rand_core/std"]
serde1 = ["serde"]
serde = ["dep:serde"]
16 changes: 8 additions & 8 deletions rand_chacha/src/chacha.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::guts::ChaCha;
use rand_core::block::{BlockRng, BlockRngCore, CryptoBlockRng};
use rand_core::{CryptoRng, RngCore, SeedableRng};

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

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

#[cfg(feature = "serde1")]
#[cfg(feature = "serde")]
impl Serialize for $ChaChaXRng {
fn serialize<S>(&self, s: S) -> Result<S::Ok, S::Error>
where
Expand All @@ -285,7 +285,7 @@ macro_rules! chacha_impl {
$abst::$ChaChaXRng::from(self).serialize(s)
}
}
#[cfg(feature = "serde1")]
#[cfg(feature = "serde")]
impl<'de> Deserialize<'de> for $ChaChaXRng {
fn deserialize<D>(d: D) -> Result<Self, D::Error>
where
Expand All @@ -296,14 +296,14 @@ macro_rules! chacha_impl {
}

mod $abst {
#[cfg(feature = "serde1")]
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

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

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

type ChaChaRng = super::ChaCha20Rng;

#[cfg(feature = "serde1")]
#[cfg(feature = "serde")]
#[test]
fn test_chacha_serde_roundtrip() {
let seed = [
Expand Down Expand Up @@ -405,7 +405,7 @@ mod test {
// However testing for equivalence of serialized data is difficult, and there shouldn't be any
// reason we need to violate the stronger-than-needed condition, e.g. by changing the field
// definition order.
#[cfg(feature = "serde1")]
#[cfg(feature = "serde")]
#[test]
fn test_chacha_serde_format_stability() {
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}"#;
Expand Down
1 change: 1 addition & 0 deletions rand_core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

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

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

Expand Down
2 changes: 1 addition & 1 deletion rand_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ all-features = true
[features]
std = ["alloc", "getrandom?/std"]
alloc = [] # enables Vec and Box support without std
serde1 = ["serde"] # enables serde for BlockRng wrapper
serde = ["dep:serde"] # enables serde for BlockRng wrapper

[dependencies]
serde = { version = "1", features = ["derive"], optional = true }
Expand Down
2 changes: 1 addition & 1 deletion rand_core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ problems where one crate implicitly requires `rand_core` with `std` support and
another crate requires `rand` *without* `std` support. However, the `rand` crate
continues to enable `std` support by default, both for itself and `rand_core`.

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


Expand Down
8 changes: 4 additions & 4 deletions rand_core/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
use crate::impls::{fill_via_u32_chunks, fill_via_u64_chunks};
use crate::{CryptoRng, RngCore, SeedableRng, TryRngCore};
use core::fmt;
#[cfg(feature = "serde1")]
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

/// A trait for RNGs which do not generate random numbers individually, but in
Expand Down Expand Up @@ -116,9 +116,9 @@ pub trait CryptoBlockRng: BlockRngCore {}
/// [`next_u64`]: RngCore::next_u64
/// [`fill_bytes`]: RngCore::fill_bytes
#[derive(Clone)]
#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(
feature = "serde1",
feature = "serde",
serde(
bound = "for<'x> R: Serialize + Deserialize<'x> + Sized, for<'x> R::Results: Serialize + Deserialize<'x>"
)
Expand Down Expand Up @@ -283,7 +283,7 @@ impl<R: CryptoBlockRng + BlockRngCore<Item = u32>> CryptoRng for BlockRng<R> {}
/// [`next_u64`]: RngCore::next_u64
/// [`fill_bytes`]: RngCore::fill_bytes
#[derive(Clone)]
#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct BlockRng64<R: BlockRngCore + ?Sized> {
results: R::Results,
index: usize,
Expand Down
2 changes: 2 additions & 0 deletions rand_distr/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased
- The `serde1` feature has been renamed `serde` (#1477)

### Added
- Add plots for `rand_distr` distributions to documentation (#1434)
- Add `PertBuilder`, fix case where mode ≅ mean (#1452)
Expand Down
2 changes: 1 addition & 1 deletion rand_distr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ alloc = ["rand/alloc"]
# feature (default-enabled) will have the same effect.
std_math = ["num-traits/std"]

serde1 = ["serde", "rand/serde1"]
serde = ["dep:serde", "rand/serde"]

[dependencies]
rand = { path = "..", version = "=0.9.0-alpha.1", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion rand_distr/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ can be enabled. (Note that any other crate depending on `num-traits` with the
- `alloc` (enabled by default): required for some distributions when not using
`std` (in particular, `Dirichlet` and `WeightedAliasIndex`).
- `std_math`: see above on portability and libm
- `serde1`: implement (de)seriaialization using `serde`
- `serde`: implement (de)seriaialization using `serde`

## Links

Expand Down
12 changes: 6 additions & 6 deletions rand_distr/src/beta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::{Distribution, Open01};
use core::fmt;
use num_traits::Float;
use rand::Rng;
#[cfg(feature = "serde1")]
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

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

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

/// Algorithm BC for `min(alpha, beta) <= 1`.
#[derive(Clone, Copy, Debug, PartialEq)]
#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
struct BC<N> {
alpha: N,
beta: N,
Expand Down Expand Up @@ -77,7 +77,7 @@ struct BC<N> {
/// println!("{} is from a Beta(2, 5) distribution", v);
/// ```
#[derive(Clone, Copy, Debug, PartialEq)]
#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Beta<F>
where
F: Float,
Expand All @@ -91,7 +91,7 @@ where

/// Error type returned from [`Beta::new`].
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum Error {
/// `alpha <= 0` or `nan`.
AlphaTooSmall,
Expand Down
2 changes: 1 addition & 1 deletion rand_distr/src/binomial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ use rand::Rng;
/// println!("{} is from a binomial distribution", v);
/// ```
#[derive(Clone, Copy, Debug, PartialEq)]
#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Binomial {
/// Number of trials.
n: u64,
Expand Down
2 changes: 1 addition & 1 deletion rand_distr/src/cauchy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ use rand::Rng;
/// Note that at least for `f32`, results are not fully portable due to minor
/// differences in the target system's *tan* implementation, `tanf`.
#[derive(Clone, Copy, Debug, PartialEq)]
#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Cauchy<F>
where
F: Float + FloatConst,
Expand Down
8 changes: 4 additions & 4 deletions rand_distr/src/chi_squared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::{Distribution, Exp1, Gamma, Open01, StandardNormal};
use core::fmt;
use num_traits::Float;
use rand::Rng;
#[cfg(feature = "serde1")]
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

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

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

#[derive(Clone, Copy, Debug, PartialEq)]
#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
enum ChiSquaredRepr<F>
where
F: Float,
Expand Down
2 changes: 1 addition & 1 deletion rand_distr/src/dirichlet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ where
}

#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
struct DirichletFromBeta<F, const N: usize>
where
F: Float,
Expand Down
Loading