Skip to content

Commit 6912a12

Browse files
committed
Add serde to rand_core
1 parent ad21dc5 commit 6912a12

File tree

4 files changed

+10
-1
lines changed

4 files changed

+10
-1
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ alloc = ["rand_core/alloc"] # enables Vec and Box support without std
2222

2323
i128_support = [] # enables i128 and u128 support
2424

25-
serde-1 = ["serde", "serde_derive"]
25+
serde-1 = ["serde", "serde_derive", "rand_core/serde-1"]
2626

2727

2828
[target.'cfg(unix)'.dependencies]

rand_core/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,8 @@ categories = ["algorithms"]
1818
# default = ["std"]
1919
std = [] # use std library; should be default but for above bug
2020
alloc = [] # enables Vec and Box support without std
21+
serde-1 = ["serde", "serde_derive"] # enables serde for BlockRng wrapper
22+
23+
[dependencies]
24+
serde = {version="1",optional=true}
25+
serde_derive = {version="1", optional=true}

rand_core/src/impls.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ pub fn next_u64_via_fill<R: RngCore + ?Sized>(rng: &mut R) -> u64 {
184184
/// [`RngCore`]: ../RngCore.t.html
185185
/// [`SeedableRng`]: ../SeedableRng.t.html
186186
#[derive(Clone)]
187+
#[cfg_attr(feature="serde-1", derive(Serialize,Deserialize))]
187188
pub struct BlockRng<R: BlockRngCore + ?Sized> {
188189
pub results: R::Results,
189190
pub index: usize,
@@ -346,6 +347,7 @@ impl<R: BlockRngCore + SeedableRng> SeedableRng for BlockRng<R> {
346347
/// [`RngCore`]: ../RngCore.t.html
347348
/// [`BlockRng`]: .BlockRng.s.html
348349
#[derive(Clone)]
350+
#[cfg_attr(feature="serde-1", derive(Serialize,Deserialize))]
349351
pub struct BlockRng64<R: BlockRngCore + ?Sized> {
350352
pub results: R::Results,
351353
pub index: usize,

rand_core/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939

4040
#[cfg(feature="std")] extern crate core;
4141
#[cfg(all(feature = "alloc", not(feature="std")))] extern crate alloc;
42+
#[cfg(feature="serde-1")] extern crate serde;
43+
#[cfg(feature="serde-1")] #[macro_use] extern crate serde_derive;
4244

4345

4446
use core::default::Default;

0 commit comments

Comments
 (0)