Skip to content

Commit

Permalink
Merge pull request #1130 from dhardy/work
Browse files Browse the repository at this point in the history
serde for BlockRng, ReseedingRng and ReadRng
  • Loading branch information
dhardy committed Jun 7, 2021
2 parents 66b1636 + d167dd2 commit 09d3df3
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Expand Up @@ -20,7 +20,7 @@ include = ["src/", "LICENSE-*", "README.md", "CHANGELOG.md", "COPYRIGHT"]
# Meta-features:
default = ["std", "std_rng"]
nightly = [] # enables performance optimizations requiring nightly rust
serde1 = ["serde"]
serde1 = ["serde", "rand_core/serde1"]

# 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 @@ -62,7 +62,7 @@ serde = { version = "1.0.103", features = ["derive"], optional = true }
[dependencies.packed_simd]
# NOTE: so far no version works reliably due to dependence on unstable features
package = "packed_simd_2"
version = "0.3.4"
version = "0.3.5"
optional = true
features = ["into_bits"]

Expand Down
6 changes: 6 additions & 0 deletions rand_core/src/block.rs
Expand Up @@ -114,6 +114,12 @@ pub trait BlockRngCore {
/// [`try_fill_bytes`]: RngCore::try_fill_bytes
#[derive(Clone)]
#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
#[cfg_attr(
feature = "serde1",
serde(
bound = "for<'x> R: Serialize + Deserialize<'x> + Sized, for<'x> R::Results: Serialize + Deserialize<'x>"
)
)]
pub struct BlockRng<R: BlockRngCore + ?Sized> {
results: R::Results,
index: usize,
Expand Down
1 change: 1 addition & 0 deletions src/rngs/adapter/mod.rs
Expand Up @@ -11,5 +11,6 @@
mod read;
mod reseeding;

#[allow(deprecated)]
pub use self::read::{ReadError, ReadRng};
pub use self::reseeding::ReseedingRng;
15 changes: 4 additions & 11 deletions src/rngs/adapter/read.rs
Expand Up @@ -9,6 +9,8 @@

//! A wrapper around any Read to treat it as an RNG.

#![allow(deprecated)]

use std::fmt;
use std::io::Read;

Expand All @@ -30,20 +32,10 @@ use rand_core::{impls, Error, RngCore};
/// have enough data, will only be reported through [`try_fill_bytes`].
/// The other [`RngCore`] methods will panic in case of an error.
///
/// # Example
///
/// ```
/// use rand::Rng;
/// use rand::rngs::adapter::ReadRng;
///
/// let data = vec![1, 2, 3, 4, 5, 6, 7, 8];
/// let mut rng = ReadRng::new(&data[..]);
/// println!("{:x}", rng.gen::<u32>());
/// ```
///
/// [`OsRng`]: crate::rngs::OsRng
/// [`try_fill_bytes`]: RngCore::try_fill_bytes
#[derive(Debug)]
#[deprecated(since="0.8.4", note="removal due to lack of usage")]
pub struct ReadRng<R> {
reader: R,
}
Expand Down Expand Up @@ -86,6 +78,7 @@ impl<R: Read> RngCore for ReadRng<R> {

/// `ReadRng` error type
#[derive(Debug)]
#[deprecated(since="0.8.4")]
pub struct ReadError(std::io::Error);

impl fmt::Display for ReadError {
Expand Down

0 comments on commit 09d3df3

Please sign in to comment.