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

  • Rust Quick Start Guide
  • Daniel Arbuckle
  • 182字
  • 2021-06-10 19:46:03

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.

主站蜘蛛池模板: 板桥市| 齐齐哈尔市| 托克托县| 大理市| 清苑县| 江达县| 洛宁县| 漠河县| 壶关县| 乐山市| 乡宁县| 兴安县| 龙井市| 墨脱县| 开阳县| 灵山县| 新闻| 宜君县| 东源县| 呼伦贝尔市| 时尚| 黑水县| 虎林市| 咸丰县| 青川县| 金秀| 武功县| 溧水县| 潞城市| 交口县| 麦盖提县| 小金县| 法库县| 高要市| 宁津县| 曲周县| 镇江市| 乐至县| 南康市| 洞口县| 五常市|