错误[E0599]:在当前范围内找不到类型为“&mut G”的名为“gen”的方法
error[E0599]: no method named `gen` found for type `&mut G` in the current scope
我正在尝试使用 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 对我来说它重现了这个问题。
这似乎是快速检查的问题。 Quickcheck uses rand version 0.6.5, whereas the newest version of rand is 0.7.0。
因为不同版本的特征不兼容 rustc 给你这个错误。
要解决它,请在版本 0.6.5 中将 rand 声明为依赖项,它将起作用。
我正在尝试使用 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 对我来说它重现了这个问题。
这似乎是快速检查的问题。 Quickcheck uses rand version 0.6.5, whereas the newest version of rand is 0.7.0。
因为不同版本的特征不兼容 rustc 给你这个错误。
要解决它,请在版本 0.6.5 中将 rand 声明为依赖项,它将起作用。