我正在编写一个名为 my_new_lib
的 Rust 库,并具有以下文件结构:
├── my_new_lib
├── src
├── lib.rs
└── file1.rs
├── tests
在lib.rs
中我定义了一个结构:
/// content of lib.rs
pub struct my_struct {}
在file1.rs
中我想使用my_struct
,例如:
/// content of file1.rs
use ????
pub struct my_second_struct {
member1: my_struct
}
我应该在 file1.rs
的 use
子句中放入什么才能使其工作?
最佳答案
您必须使用 crate
关键字来访问您的 crate 的根目录:
use crate::MyStruct;
关于module - 如何将来自主模块的类型包含在同一个 crate 的其他文件中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54287835/