官术网_书友最值得收藏!

Using the item's short name

We can also use the use keyword to tell Rust that we want to refer to an item in a different module by its short name. This is done by just writing use followed by the full name of the item we want to use. For example, use std::path::Path; allows us to use just the short name for that item (Path in this example) in the following instructions, until we come to the } that closes the section of code where our use keyword was written (or we come to the end of the module file, which amounts to the same thing).

We can use the same syntax to tell Rust that we want to use the name of a module, rather than an item in a module. For example, std::path is a valid command. That would allow us to use path::Path as the name of the Path item in subsequent code. This is frequently convenient, since it still keeps the external items boxed up and separate, while providing reasonably short and informative names to work with.

主站蜘蛛池模板: 长阳| 英德市| 会东县| 滁州市| 临猗县| 新密市| 会同县| 德庆县| 金堂县| 来宾市| 织金县| 江都市| 南开区| 瑞丽市| 西平县| 平顺县| 农安县| 靖宇县| 万州区| 泰顺县| 定陶县| 六安市| 古浪县| 绍兴县| 四平市| 禹州市| 正镶白旗| 云林县| 彭水| 新绛县| 七台河市| 合山市| 临澧县| 重庆市| 孝义市| 神农架林区| 依兰县| 新乡县| 濮阳县| 怀来县| 雷州市|