Last active
December 23, 2020 18:59
-
-
Save ulidtko/c67e7a7d000c0ac81d69c1f7dfba4fce to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [package] | |
| name = "foobar" | |
| version = "0.1.0" | |
| authors = ["max ulidtko <[email protected]>"] | |
| edition = "2018" | |
| # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | |
| [dependencies] | |
| rand = "0.8.*" | |
| quickcheck = "0.9.*" | |
| [[bin]] | |
| name = "foobar" | |
| path = "main.rs" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Compiling foobar v0.1.0 (/tmp/foobar) | |
| error[E0277]: the trait bound `G: rand::RngCore` is not satisfied | |
| --> src/main.rs:20:28 | |
| | | |
| 8 | fn new_random<R: Rng>(rng: &mut R) -> Self { | |
| | --- required by this bound in `Foobar::new_random` | |
| ... | |
| 20 | Foobar::new_random(g) | |
| | ^ the trait `rand::RngCore` is not implemented for `G` | |
| | | |
| = note: required because of the requirements on the impl of `rand::Rng` for `G` | |
| help: consider further restricting this bound | |
| | | |
| 19 | fn arbitrary<G: Gen + rand::RngCore>(g: &mut G) -> Self { | |
| | ^^^^^^^^^^^^^^^ | |
| error: aborting due to previous error | |
| For more information about this error, try `rustc --explain E0277`. | |
| error: could not compile `foobar` | |
| To learn more, run the command again with --verbose. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extern crate rand; | |
| use rand::prelude::*; | |
| #[derive(Debug,Clone)] | |
| enum Foobar { Foo, Bar } | |
| impl Foobar { | |
| fn new_random<R: Rng>(rng: &mut R) -> Self { | |
| match rng.gen() { | |
| true => Foobar::Foo, | |
| false => Foobar::Bar, | |
| } | |
| } | |
| } | |
| extern crate quickcheck; | |
| use quickcheck::{Gen,Arbitrary}; | |
| impl Arbitrary for Foobar { | |
| fn arbitrary<G: Gen>(g: &mut G) -> Self { | |
| Foobar::new_random(g) | |
| } | |
| } | |
| fn main() { | |
| let mut rng = rand::thread_rng(); | |
| println!("{:?}", Foobar::new_random(&mut rng)); | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Fix
to avoid this: