rust-2018

How to idiomatically alias a crate in Rust 2018?

末鹿安然 提交于 2019-12-17 09:59:46
问题 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 anymore and I don't want to use it only for aliasing. When dropping extern crate , I get error[E0463]: can't find crate for foo 回答1: This can be achieved with the rename-dependency Cargo feature, available in Rust 1.31. With this feature, it's possible to provide a package attribute to the dependencies: The rename-dependency feature allows you to import a

How to import all macros, derives, and procedural macros in Rust 2018 without using extern crate?

Deadly 提交于 2019-12-10 03:51:31
问题 I'm experimenting with Rust Edition 2018. In Rust 2015 you use #[macro_use] extern crate log; for importing macros. In Rust 2018 extern crate is probably unidiomatic. Is there a way, to import all macros from the crate without extern crate ? For simple macros, importing it in the modules is fine, but complicated macros depend on several other macros, which is unhandy. 回答1: I don't see any way of importing only all the macros, but if you are fine with importing all the essential objects a

What are the use cases of raw identifiers besides new keywords?

陌路散爱 提交于 2019-11-28 05:37:45
问题 As in Rust 2018, we now have raw identifiers: This feature is useful for a few reasons, but the primary motivation was inter-edition situations. For example, try is not a keyword in the 2015 edition, but is in the 2018 edition. So if you have a library that is written in Rust 2015 and has a try function, to call it in Rust 2018, you'll need to use the raw identifier. Are there any other advantages than stated above? Are there plans to make keywords contextual, e.g. you can use type as

What are the valid path roots in the use keyword?

耗尽温柔 提交于 2019-11-27 04:07:39
问题 With the module system being revamped for the 2018 edition, the functioning of the use keyword has changed. What are the valid paths that can go after the use keyword? 回答1: Paths in use statements can only start in the following ways: name of an extern crate : then it refers to that extern crate crate : refers to the (top level of your) own crate self : refers to the current module super : refers to the parent module other name : in this case, it looks for that name relative to the current