Skip to content

rand: bump to 0.9 #60

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
[package]
name = "ark-std"
version = "0.5.0"
authors = [ "arkworks contributors" ]
authors = ["arkworks contributors"]
description = "A library for no_std compatibility"
homepage = "https://arkworks.rs"
repository = "https://github.com/arkworks-rs/std"
documentation = "https://docs.rs/ark-std/"
keywords = [ "no_std" ]
keywords = ["no_std"]
categories = ["cryptography"]
include = ["Cargo.toml", "src", "README.md", "LICENSE-APACHE", "LICENSE-MIT"]
license = "MIT/Apache-2.0"
edition = "2021"

[dependencies]
rand = { version = "0.8", default-features = false, features = ["std_rng"]}
rand = { version = "0.9", default-features = false, features = ["std_rng"] }
rayon = { version = "1", optional = true }
colored = { version = "2", optional = true }
colored = { version = "3", optional = true }
num-traits = { version = "0.2", default-features = false }

[dev-dependencies]
rand = { version = "0.8", features = ["std"]}
rand = { version = "0.9", features = ["std"] }


[features]
default = [ "std" ]
default = ["std"]
std = []
parallel = [ "rayon", "std" ]
print-trace = [ "std", "colored" ]
parallel = ["rayon", "std"]
print-trace = ["std", "colored"]
getrandom = ["rand/std"]

[profile.bench]
Expand Down
10 changes: 5 additions & 5 deletions src/perf_trace.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![allow(unused_imports)]
//! This module contains macros for logging to stdout a trace of wall-clock time required
//! to execute annotated code. One can use this code as follows:
//! This module contains macros for logging to stdout a trace of wall-clock time
//! required to execute annotated code. One can use this code as follows:
//! ```
//! use ark_std::{start_timer, end_timer};
//! let start = start_timer!(|| "Addition of two integers");
Expand All @@ -13,8 +13,8 @@
//! End: Addition of two integers... 1ns
//! ```
//!
//! These macros can be arbitrarily nested, and the nested nature is made apparent
//! in the output. For example, the following snippet:
//! These macros can be arbitrarily nested, and the nested nature is made
//! apparent in the output. For example, the following snippet:
//! ```
//! use ark_std::{start_timer, end_timer};
//! let start = start_timer!(|| "Addition of two integers");
Expand Down Expand Up @@ -162,7 +162,7 @@ pub mod inner {
pub fn compute_indent_whitespace(indent_amount: usize) -> String {
let mut indent = String::new();
for _ in 0..indent_amount {
indent.push_str(" ");
indent.push(' ');
}
indent
}
Expand Down
23 changes: 7 additions & 16 deletions src/rand_helper.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#[cfg(feature = "std")]
use rand::RngCore;
use rand::{
distributions::{Distribution, Standard},
distr::{Distribution, StandardUniform},
prelude::StdRng,
Rng,
};
Expand All @@ -14,11 +14,11 @@ pub trait UniformRand: Sized {

impl<T> UniformRand for T
where
Standard: Distribution<T>,
StandardUniform: Distribution<T>,
{
#[inline]
fn rand<R: Rng + ?Sized>(rng: &mut R) -> Self {
rng.sample(Standard)
rng.sample(StandardUniform)
}
}

Expand Down Expand Up @@ -46,21 +46,21 @@ pub fn test_rng() -> impl rand::Rng {
let is_deterministic =
std::env::vars().any(|(key, val)| key == "DETERMINISTIC_TEST_RNG" && val == "1");
if is_deterministic {
RngWrapper::Deterministic(test_rng_helper())
RngWrapper::Deterministic(Box::new(test_rng_helper()))
} else {
RngWrapper::Randomized(rand::thread_rng())
RngWrapper::Randomized(rand::rng())
}
}
#[cfg(not(any(feature = "getrandom", test)))]
{
RngWrapper::Deterministic(test_rng_helper())
RngWrapper::Deterministic(Box::new(test_rng_helper()))
}
}

/// Helper wrapper to enable `test_rng` to return `impl::Rng`.
#[cfg(feature = "std")]
enum RngWrapper {
Deterministic(StdRng),
Deterministic(Box<StdRng>),
#[cfg(any(feature = "getrandom", test))]
Randomized(rand::rngs::ThreadRng),
}
Expand Down Expand Up @@ -93,15 +93,6 @@ impl RngCore for RngWrapper {
Self::Randomized(rng) => rng.fill_bytes(dest),
}
}

#[inline(always)]
fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), rand::Error> {
match self {
Self::Deterministic(rng) => rng.try_fill_bytes(dest),
#[cfg(any(feature = "getrandom", test))]
Self::Randomized(rng) => rng.try_fill_bytes(dest),
}
}
}

#[cfg(all(test, feature = "std"))]
Expand Down