-
Notifications
You must be signed in to change notification settings - Fork 521
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
Chapter 6.5 - quickcheck 1.0 has changed trait Gen to struct Gen with no trait RngCore #34
Comments
Thanks for reporting the issue! |
For the time being I have pinned |
A related issue, after pasting the dependenecies in
We get
After changing to
Using the version Putting all of these here, as it will be resolved by what you linked above. |
@cedeerwe I could only get quickcheck to work with quickcheck = "0.9"
quickcheck_macros = "0.9" |
The latest release adopts @cedeerwe's fix - it pins |
I ended up doing this until the compiler stopped yelling at me. Not elegant but it works for now: #[derive(Debug, Clone)]
struct ValidEmailFixture(String);
impl quickcheck::Arbitrary for ValidEmailFixture {
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
let mut rand_slice: [u8; 32] = [0; 32];
for i in 0..32 {
rand_slice[i] = u8::arbitrary(g);
}
let mut seed = StdRng::from_seed(rand_slice);
let email = SafeEmail().fake_with_rng(&mut seed);
println!("{}", email);
Self(email)
} Had to add rand and rand_core to the dev dependencies. Is there a better way to achieve this? Just asking out of curiosity. |
I think this is better: let mut rng = StdRng::seed_from_u64(u64::arbitrary(g)); |
Still seeing this with the latest examples from the book, and from this codebase @LukeMathWalker Seems like pinning |
This indeed on |
Pinning still required as of December 2022, however the suggestion above (#34 (comment)) ends up being fairly clean in practice: use rand::{rngs::StdRng, SeedableRng};
//[ ... ]
impl Arbitrary for ValidEmailFixture {
fn arbitrary(g: &mut Gen) -> Self {
let mut rng = StdRng::seed_from_u64(u64::arbitrary(g));
let email = SafeEmail().fake_with_rng(&mut rng);
Self(email)
}
} |
#34 (comment) works, and if and until a new edition of the book is released, the code and dependencies have to stay the same, but for people like me, I'd appreciate a "sneak peek" in this thread regarding how this would be implemented if the book had been written with today's crate ecosystem in mind. Would it still use |
The code in #34 works for me with the following:
|
I am now getting the following error:
When using the proposed solution above comment Not sure if this is a
I will keep digging for a solution and update this thread if I find one, but still wanted to share as it seems there are other issues in this area Update: I think I got my solutions mixed up, when downgrading the impl quickcheck::Arbitrary for ValidEmailFixture {
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
let email = SafeEmail().fake_with_rng(g);
Self(email)
}
} |
Pinning seems no longer necessary. [dev-dependencies]
fake = "2.6.1"
rand = "0.8.5"
quickcheck = "1.0.3"
quickcheck_macros = "1.0.0" #[derive(Debug, Clone)]
struct ValidEmailFixture(pub String);
impl quickcheck::Arbitrary for ValidEmailFixture {
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
let mut rng = StdRng::seed_from_u64(u64::arbitrary(g));
let email = SafeEmail().fake_with_rng(&mut rng);
Self(email)
}
}
#[quickcheck_macros::quickcheck]
fn valid_emails_are_parsed_successfully(valid_email: ValidEmailFixture) -> bool {
SubscriberEmail::parse(valid_email.0).is_ok()
} |
Sweet! |
- Reference: LukeMathWalker/zero-to-production#34 - Update `fake` to 2.6 and `quickcheck` to 1 - `fake` 2.6 depending on `rand` 0.8
This has been fixed in the next book release. Closing! |
As result of the change the book code is not compiled.
I suggest adding specific versions to these commands in the book or update code ;)
Changes:
before
now -> link to the source code
The text was updated successfully, but these errors were encountered: