- 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.
- Django+Vue.js商城項(xiàng)目實(shí)戰(zhàn)
- Android應(yīng)用程序開發(fā)與典型案例
- Photoshop智能手機(jī)APP UI設(shè)計(jì)之道
- 無(wú)代碼編程:用云表搭建企業(yè)數(shù)字化管理平臺(tái)
- The HTML and CSS Workshop
- 從Excel到Python:用Python輕松處理Excel數(shù)據(jù)(第2版)
- PHP 7+MySQL 8動(dòng)態(tài)網(wǎng)站開發(fā)從入門到精通(視頻教學(xué)版)
- Java網(wǎng)絡(luò)編程核心技術(shù)詳解(視頻微課版)
- 小程序,巧應(yīng)用:微信小程序開發(fā)實(shí)戰(zhàn)(第2版)
- Python入門很輕松(微課超值版)
- Mudbox 2013 Cookbook
- AMP:Building Accelerated Mobile Pages
- 基于GPU加速的計(jì)算機(jī)視覺(jué)編程:使用OpenCV和CUDA實(shí)時(shí)處理復(fù)雜圖像數(shù)據(jù)
- 少年小魚的魔法之旅:神奇的Python
- Scratch少兒編程高手的7個(gè)好習(xí)慣