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

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.

主站蜘蛛池模板: 彰武县| 老河口市| 安福县| 永昌县| 泾川县| 达孜县| 米林县| 广南县| 鹤庆县| 威远县| 德昌县| 商城县| 东安县| 静乐县| 奈曼旗| 封开县| 壤塘县| 罗山县| 东乌珠穆沁旗| 阳春市| 琼中| 开平市| 昭苏县| 奉化市| 泸溪县| 铜川市| 岱山县| 萨迦县| 陈巴尔虎旗| 右玉县| 区。| 海城市| 五家渠市| 察雅县| 武胜县| 屯留县| 旺苍县| 英超| 永安市| 监利县| 眉山市|