在 Rust 中测试自定义对象

问题描述 投票:0回答:1

我想测试 Rust 中链表的自定义实现。项目的结构就是图中的结构

现在我已经使用

pub mod linked_list {...}
来导出它,然后使用
use linked_list::LinkedList
导入测试/linked_list 来编写我的测试并使用我的自定义 LinkedList 对象。当我运行
cargo test
时,我收到错误

let mut list = LinkedList::new();
   |                        ^^^^^^^^^^ use of undeclared type `LinkedList`

我不知道如何根据之前的项目架构正确导入我的模块。我还需要在 main.rs 中插入一些东西吗?

testing rust rust-cargo
1个回答
0
投票

如果

linked_list.rs
data_structure
目录中,那么你必须执行以下操作:

  • src/data_structure.rs
    ,
     创建 
    pub mod linked_list;
  • src/main.rs
    中添加
    pub mod data_structure;
    ,
  • 最后,在
    src/main.rs
    中调整
    use data_structure::linked_list::linked_list;
© www.soinside.com 2019 - 2024. All rights reserved.