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

  • Mastering Rust
  • Rahul Sharma Vesa Kaihlavirta
  • 208字
  • 2021-07-02 13:35:19

Cargo and crates

When projects get large, a usual practice is to refactor code into smaller, more manageable units as modules or libraries. You also need tools to render documentation for your project, how it should be built, and what libraries it depends on. Furthermore, to support the language ecosystem where developers can share their libraries with the community, an online registry of some sort is often the norm these days.

Cargo is the tool that empowers you to do all these things, and https://crates.io is the centralized place for hosting libraries. A library written in Rust is called a crate, and crates.io hosts them for developers to use. Usually, a crate can come from three sources: a local directory, an online Git repository like GitHub, or a hosted crate registry like crates.io. Cargo supports crates from all of these sources.

Let's see Cargo in action. If you ran rustup, as described in the previous chapter, you will already have cargo installed, along with rustc. To see what commands are available to us, we can run cargo without any parameters:

It shows a list of common commands that we can use, along with some flags. Let's use the the new subcommand to create a new Cargo project.

主站蜘蛛池模板: 孝感市| 凭祥市| 峡江县| 集安市| 吉木乃县| 格尔木市| 芦溪县| 景谷| 襄垣县| 大足县| 武穴市| 于都县| 阿城市| 钟山县| 岚皋县| 新泰市| 白银市| 崇仁县| 兴宁市| 枣庄市| 敦煌市| 塘沽区| 维西| 梓潼县| 偃师市| 滁州市| 武强县| 丰顺县| 三江| 潜江市| 乌什县| 山东| 双柏县| 昌平区| 平遥县| 本溪市| 吉木乃县| 黎平县| 施甸县| 封开县| 砚山县|