How to idiomatically alias a crate in Rust 2018?

前端 未结 2 858
心在旅途
心在旅途 2020-12-04 01:40

I have a crate foo_sys. In Rust 2015 I used extern crate foo_sys as foo for convenience, but in Rust 2018 extern crate isn\'t needed a

2条回答
  •  情歌与酒
    2020-12-04 02:01

    The idiomatic solution is to rename the crate in Cargo.toml. See the answer by Tim Diekmann for more information about that.

    But if you don't want to use Cargo.toml renaming for some reason, you can still use the old syntax. It's soft-deprecated, but not removed. So this still works:

    extern crate foo_sys as foo;
    

    (Playground example)

提交回复
热议问题