如何在src中布局我的Rust模块,以便在我的应用程序中访问
我已经创建了一个包结构,但是编译器说它找不到我的模块。我是新手,有Java&C背景# 我尝试过使用self和super前缀,但无法编译代码 我的结构如下:如何在src中布局我的Rust模块,以便在我的应用程序中访问,rust,Rust,我已经创建了一个包结构,但是编译器说它找不到我的模块。我是新手,有Java&C背景# 我尝试过使用self和super前缀,但无法编译代码 我的结构如下: src |_lib.rs |_common | |_mod.rs | |_service.rs | |_animals |_mod.rs |_domestic | |_mod.rs | |_dog.rs |_wild |_mod.rs 以下是简化文件: 狗粮 pub struct Dog { ... } imp
src
|_lib.rs
|_common
| |_mod.rs
| |_service.rs
|
|_animals
|_mod.rs
|_domestic
| |_mod.rs
| |_dog.rs
|_wild
|_mod.rs
以下是简化文件:
狗粮
pub struct Dog {
...
}
impl Dog {
...
}
国内>国防部
pub mod dog;
动物>mod.rs
pub mod domestic;
pub mod wild;
src>lib.rs
pub mod common;
pub mod animals;
公共>服务
use animals::domestic::dog;
从我在铁锈书中读到的(可能是误解的)来看,这应该是可行的
但是编译器抛出以下错误:
could not find `animals` in `{{root}}`
我是不是用“生锈”的方式写的?我需要修改什么才能编译它呢
感谢
commons>服务中的
use crate::animals::domestic::dog;
crate
关键字告诉编译器从包的根开始;i、 接下来是一条绝对路径
或者,您可以使用相对路径并使用super
关键字向上移动一级
有关详细信息,请参见
commons>服务中的
use crate::animals::domestic::dog;
crate
关键字告诉编译器从包的根开始;i、 接下来是一条绝对路径
或者,您可以使用相对路径并使用super
关键字向上移动一级
有关详细信息,请参见。您没有src/lib.rs
?是的,我有lib.rs。我已将其添加到描述中。我发帖时只是疏忽了一下。你没有src/lib.rs
?是的,我有lib.rs。我已将其添加到描述中。只是我发帖时的疏忽。