我有一个箱子 foo_sys 。在 Rust 2015 中,为了方便起见,我使用了 extern crate foo_sys as foo,但在 Rust 2018 中不再需要 extern crate,我不想仅将它用于别名。删除 extern crate 时,我得到

最佳答案

这可以通过 rename-dependency Cargo 功能 available in Rust 1.31 来实现。使用此功能,可以为依赖项提供包属性:

而不是写作

[dependencies]
foo_sys = "0.2"
package 键可以添加到 Cargo.toml 的依赖项中:
[dependencies]
foo = { package = "foo_sys", version = "0.2" }
警告 : Cargo prior to Rust 1.26.0 may download the wrong dependency 使用此功能时!

关于rust - 如何在 Rust 2018 中惯用别名一个 crate ?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53311325/

10-11 22:23
查看更多