Skip to content

Commit

Permalink
rand: remove rand as a public dependency
Browse files Browse the repository at this point in the history
This removes the use of the rand_core crate as a public dependency. It
is now an implementation detail.

We achieve this primarily by turning the `Gen` trait into a concrete
type and fixing the fallout.

This does make it impossible for callers to use their own `Gen`
implementations, but it's unclear how often this was being used (if at
all). This does also limit the number of RNG utility routines that
callers have easy access to. However, it should be possible to use
rand's `SeedableRng::from_{rng,seed}` routines to get access to more
general RNGs.

Closes #241
  • Loading branch information
BurntSushi committed Dec 27, 2020
1 parent b2a6ba6 commit 57ba0d1
Show file tree
Hide file tree
Showing 6 changed files with 184 additions and 245 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ name = "quickcheck"
[dependencies]
env_logger = { version = "0.7.0", default-features = false, optional = true }
log = { version = "0.4", optional = true }
rand = "0.7"
rand = { version = "0.7", features = ["small_rng"] }
rand_core = "0.5"
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ trait. Great, so what is this `Testable` business?

```rust
pub trait Testable {
fn result<G: Gen>(&self, &mut G) -> TestResult;
fn result(&self, &mut Gen) -> TestResult;
}
```

Expand All @@ -207,7 +207,7 @@ Sure enough, `bool` satisfies the `Testable` trait:

```rust
impl Testable for bool {
fn result<G: Gen>(&self, _: &mut G) -> TestResult {
fn result(&self, _: &mut Gen) -> TestResult {
TestResult::from_bool(*self)
}
}
Expand All @@ -218,7 +218,7 @@ satisfy `Testable` too!

```rust
impl<A: Arbitrary + Debug, B: Testable> Testable for fn(A) -> B {
fn result<G: Gen>(&self, g: &mut G) -> TestResult {
fn result(&self, g: &mut Gen) -> TestResult {
// elided
}
}
Expand All @@ -236,7 +236,7 @@ make sure `TestResult` satisfies `Testable`:

```rust
impl Testable for TestResult {
fn result<G: Gen>(&self, _: &mut G) -> TestResult { self.clone() }
fn result(&self, _: &mut Gen) -> TestResult { self.clone() }
}
```

Expand Down Expand Up @@ -406,7 +406,7 @@ the trait `Arbitrary` for the struct `Point`:
use quickcheck::{Arbitrary, Gen};

impl Arbitrary for Point {
fn arbitrary<G: Gen>(g: &mut G) -> Point {
fn arbitrary(g: &mut Gen) -> Point {
Point {
x: i32::arbitrary(g),
y: i32::arbitrary(g),
Expand Down
Loading

0 comments on commit 57ba0d1

Please sign in to comment.