【发布时间】:2019-11-16 00:34:30
【问题描述】:
我正在尝试使用quickcheck crate。
我已经为结构 Point {x: u32, y: u32} 实现了 Arbitrary
impl Arbitrary for Point {
fn arbitrary<G: Gen>(g: &mut G) -> Point {
let x = g.gen::<u32>();
let y = g.gen::<u32>();
Point { x, y }
}
}
编译器说:
error[E0599]: no method named `gen` found for type `&mut G` in the current scope
--> src/main.rs:61:23
|
61 | let x = g.gen::<u32>();
| ^^^
|
= note: the method `gen` exists but the following trait bounds were not satisfied:
`&mut G : rand::Rng`
`G : rand::Rng`
= help: items from traits can only be used if the trait is in scope
= note: the following trait is implemented but not in scope, perhaps add a `use` for it:
`use rand::Rng;`
但我在测试模块中有use rand:Rng;,在我的 Cargo.toml 中有rand 作为开发依赖项。
我在模块中也有use quickcheck::{quickcheck, Arbitrary, Gen};。
为了创建任意生成器,我缺少什么?
--- 编辑 --- 如果您想为我运行https://gist.github.com/russelldb/49b96ca2e23dfab8a0f03090144735e4,它会重现问题。
【问题讨论】:
-
请提供minimal reproducible example,因为您的代码对我来说看起来不错,所以错误一定在其他地方。
-
顶部的
use rand::Rng;不能解决问题吗? -
我有一个使用 rand::Rng;。我会尝试发布一个 MRE。
-
这里有一个最小的(小?)repro ex gist.github.com/russelldb/49b96ca2e23dfab8a0f03090144735e4。提前致谢。
-
@russelldb 请将其包含在此问题中,而不是使用 github。请edit你的问题:)
标签: rust quickcheck