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

  • 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.

主站蜘蛛池模板: 太仓市| 云浮市| 方城县| 南汇区| 玛曲县| 时尚| 新安县| 得荣县| 浪卡子县| 西峡县| 尉氏县| 博白县| 天台县| 黑河市| 祁门县| 扶沟县| 静乐县| 德安县| 赣榆县| 吉林市| 毕节市| 忻城县| 金华市| 扎鲁特旗| 永昌县| 措美县| 柳江县| 将乐县| 吴堡县| 西平县| 安达市| 荥经县| 三门峡市| 镶黄旗| 柳江县| 合肥市| 乌鲁木齐市| 平昌县| 大石桥市| 冕宁县| 洛浦县|