我正在 Rust 中进行大量测试,以检查库中的每个函数是否运行良好。其中一些函数在参数中采用指向结构的指针。因此,我在一个单独的文件
list.rs
中编写了这个结构的样子,并且我打算在需要这种类型进行测试的其他文件中使用它。但是,当我将 use crate::t_list
放入测试文件中时,由于我不太明白的原因,我收到以下错误:
error[E0432]: unresolved import `crate::t_list`
--> tests/ft_list_push_front.rs:1:5
|
1 | use crate::t_list;
| ^^^^^^^^^^^^^ no `t_list` in the root
我有以下文件层次结构:
.
├── libasm.a
└── libasm_tester
├── build.rs
├── Cargo.toml
├── src
│ ├── list.rs
│ └── main.rs
└── tests
└── ft_list_push_front.rs
包含以下内容:
列表.rs:
use std::ffi::c_void;
#[repr(C)]
pub struct t_list {
pub data: *mut c_void,
pub next: *mut t_list,
}
main.rs:
fn main() {
println!("Run `cargo test` to test your libasm!");
}
ft_list_push_front.rs:
use crate::t_list;
use std::{
ffi::{c_void, CString},
ptr::{null, null_mut},
};
extern "C" {
fn ft_list_push_front(list: *mut *mut t_list, data: *const c_void) -> ();
}
#[test]
fn ft_list_push_front_00() {
/* ... */
}
这样做,我希望能够毫无问题地运行
cargo test
,但似乎由于某些我不知道的原因,货物在编译时找不到我的t_list
声明。我还是 Rust 和 Cargo 的初学者,所以如果有人比我更专家可以帮助我,我将非常感激。
祝你有美好的一天!
您在
t_list
内部有 list.rs
,但您尚未在任何地方声明 list
模块。
在您的
main.rs
中,您可能想添加 pub mod list;
,然后您就可以 use crate::list::t_list;
。