Skip to content

Commit

Permalink
Add serde to rand_core
Browse files Browse the repository at this point in the history
  • Loading branch information
pitdicker committed Mar 24, 2018
1 parent ad21dc5 commit 6912a12
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ alloc = ["rand_core/alloc"] # enables Vec and Box support without std

i128_support = [] # enables i128 and u128 support

serde-1 = ["serde", "serde_derive"]
serde-1 = ["serde", "serde_derive", "rand_core/serde-1"]


[target.'cfg(unix)'.dependencies]
Expand Down
5 changes: 5 additions & 0 deletions rand_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,8 @@ categories = ["algorithms"]
# default = ["std"]
std = [] # use std library; should be default but for above bug
alloc = [] # enables Vec and Box support without std
serde-1 = ["serde", "serde_derive"] # enables serde for BlockRng wrapper

[dependencies]
serde = {version="1",optional=true}
serde_derive = {version="1", optional=true}
2 changes: 2 additions & 0 deletions rand_core/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ pub fn next_u64_via_fill<R: RngCore + ?Sized>(rng: &mut R) -> u64 {
/// [`RngCore`]: ../RngCore.t.html
/// [`SeedableRng`]: ../SeedableRng.t.html
#[derive(Clone)]
#[cfg_attr(feature="serde-1", derive(Serialize,Deserialize))]
pub struct BlockRng<R: BlockRngCore + ?Sized> {
pub results: R::Results,
pub index: usize,
Expand Down Expand Up @@ -346,6 +347,7 @@ impl<R: BlockRngCore + SeedableRng> SeedableRng for BlockRng<R> {
/// [`RngCore`]: ../RngCore.t.html
/// [`BlockRng`]: .BlockRng.s.html
#[derive(Clone)]
#[cfg_attr(feature="serde-1", derive(Serialize,Deserialize))]
pub struct BlockRng64<R: BlockRngCore + ?Sized> {
pub results: R::Results,
pub index: usize,
Expand Down
2 changes: 2 additions & 0 deletions rand_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@

#[cfg(feature="std")] extern crate core;
#[cfg(all(feature = "alloc", not(feature="std")))] extern crate alloc;
#[cfg(feature="serde-1")] extern crate serde;
#[cfg(feature="serde-1")] #[macro_use] extern crate serde_derive;


use core::default::Default;
Expand Down

0 comments on commit 6912a12

Please sign in to comment.