【发布时间】:2020-06-08 22:50:44
【问题描述】:
我正在尝试使用 Rust 配置一个示例项目。
我的结构是:
src/potter.rstests/tests.rs
还有我的Cargo.toml
[package]
name = "potter"
version = "0.1.0"
authors = ["my name"]
[dependencies]
我的potter.rs 包含:
pub mod potter {
pub struct Potter {
}
impl Potter {
pub fn new() -> Potter {
return Potter {};
}
}
}
我的tests.rs 包含:
use potter::Potter;
#[test]
fn it_works() {
let pot = potter::Potter::new();
assert_eq!(2 + 2, 4);
}
但我收到此错误:
error[E0432]: unresolved import `potter`
--> tests/tests.rs:1:5
|
1 | use potter::Potter;
| ^^^^^^ Maybe a missing `extern crate potter;`?
error[E0433]: failed to resolve. Use of undeclared type or module `potter`
--> tests/tests.rs:6:19
|
6 | let pot = potter::Potter::new();
| ^^^^^^ Use of undeclared type or module `potter`
warning: unused import: `potter::Potter`
--> tests/tests.rs:1:5
|
1 | use potter::Potter;
| ^^^^^^^^^^^^^^
|
= note: #[warn(unused_imports)] on by default
如果我添加extern crate potter;,它不会解决任何问题...
error[E0463]: can't find crate for `potter`
--> tests/tests.rs:1:1
|
1 | extern crate potter;
| ^^^^^^^^^^^^^^^^^^^^ can't find crate
【问题讨论】:
-
我删除了
pub mod potter,错误仍然存在。 -
我从重复的答案中应用了解决方案,它似乎不起作用。
-
我将我的 potter.rs 重命名为 lib.rs 但它一直无法正常工作...
标签: rust