https://doc.rust-lang.org/reference/paths.html#path-qualifiers
所以你的想法是正确的,它从箱根解决。Paths can be denoted with various leading qualifiers to change the meaning of how it is resolved.
::
Paths starting with
::
are considered to be global paths where the segments of the path start being resolved from the crate root. Each identifier in the path must resolve to an item.
libc
本身并没有在箱根中定义任何内容,相反,箱根重新导出与编译目标匹配的子模块的内容。fixed_width_ints
和unix
子模块公开的所有内容。前者对你来说并不真正有用,但后者......确实定义了符号。这种语法在libc
中可行,因为它使用了Rust的2015版进行编译。与路径相关的参考资料包括以下说明:
版本差异:在2015版中,crate root包含各种不同的项,包括外部 crate、默认 crate(如std和core)以及crate顶层的项(包括use导入)。
从2018版开始,以::开头的路径只能引用 crates。
在2015年,::c_uint
将找到重新导出的类型,而在2018年则不会。有许多模块解析更改,在版本指南中有更详细的说明。
您可以在playground上测试它(您可以在Debug和Stable旁边的高级选项菜单中更改版本)。
crate::
时,它可以正常编译。你有什么想法,我在重新导出时漏掉了什么吗?我在lib.rs中使用了“mod submodule;”,然后使用“pub use submodule::*”重新导出。 - bornfree