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

  • Learning Rust
  • Paul Johnson Vesa Kaihlavirta
  • 238字
  • 2021-07-02 23:07:13

Creating a binary package using Cargo

As with any other script, Cargo works (by default) on the current working directory. (For example, while writing this chapter, my working directory for the example code is ~/Developer/Rust/chapter0 on the Mac and Linux boxes, and J:\Developer\Rust\Chapter0 on the Windows 10 machine.)

In its simplest form, Cargo can generate the correct file structure like this:

cargo new demo_app_name -bin 

The preceding command tells Cargo to create a new structure called demo_app_name, and that it is to be a binary. If you remove -bin, it creates a structure called, which is going to be a library (or more accurately, something other than a binary).

If you don't wish to use the root (say you want to create a library within your binary framework), then instead of demo_app_name, you append the structure before the name relating to your working directory.

In the small example I gave earlier, if I wanted to create a library within my binary structure, I would use the following:

cargo new app_name/mylib  

That will create a structure like this:

The Cargo.toml file requires no editing (at this stage), as it contains the information we had to enter manually when we created the project by hand.

Cargo has a number of directory separator translators. This means that the preceding example can be used on OS X, Linux, and Windows without an issue; Cargo has converted the / to \ for Windows.

主站蜘蛛池模板: 秭归县| 应城市| 永寿县| 尚义县| 珲春市| 河曲县| 宽城| 吴江市| 怀来县| 图木舒克市| 蛟河市| 琼海市| 龙海市| 湖北省| 齐河县| 石家庄市| 来宾市| 中超| 信丰县| 江津市| 蚌埠市| 仁寿县| 上犹县| 锡林浩特市| 长寿区| 博罗县| 西宁市| 衡南县| 赫章县| 历史| 芦溪县| 连平县| 丰原市| 深泽县| 曲沃县| 嘉定区| 夏津县| 大姚县| 宁蒗| 阿拉尔市| 哈尔滨市|