- Rust Programming By Example
- Guillaume Gomez Antoni Boucher
- 272字
- 2021-07-02 19:12:55
Test your installation
Let's try to build a Rust program. First, create a new project with cargo:
$ cargo new --bin hello_world Created binary (application) `hello_world` project
The --bin flag indicates that we want to create an executable project, as opposed to a library (which is the default without this flag). In the Rust world, a crate is a package of libraries and/or executable binaries.
This created a hello_world directory containing the following files and directory:
$ tree hello_world/ hello_world/ ├── Cargo.toml └── src └── main.rs 1 directory, 2 files
The Cargo.toml file is where the metadata (name, version, and so on) of your project resides, as well as its dependencies. The source files of your project are in the src directory. It's now time to run this project:
$ cd hello_world/ $ cargo run Compiling hello_world v0.1.0 (file:///home/packtpub/projects/hello_world) Finished dev [unoptimized + debuginfo] target(s) in 0.39 secs Running `target/debug/hello_world` Hello, world!
The first three lines printed after cargo run are lines printed by cargo indicating what it did: it compiled the project and ran it. The last line, Hello, world!, is the line printed by our project. As you can see, cargo generates a Rust file that prints text to stdout (standard output):
$ cat src/main.rs fn main() { println!("Hello, world!"); }
If you only want to compile the project without running it, type the following instead:
$ cargo build Finished dev [unoptimized + debuginfo] target(s) in 0.0 secs
This time, we didn't see Compiling hello_world because cargo did not see any changes to the project's files, thus, there's no need to compile again.
- 專業(yè)圖書館發(fā)展之道
- 公共圖書館動漫服務(wù)研究
- 國外圖書館動漫資源建設(shè)與服務(wù)
- 新時代檔案工作新思維
- 高校圖書館門戶網(wǎng)站建設(shè)(谷臻小簡·AI導(dǎo)讀版)
- 中國人民大學(xué)“復(fù)印報刊資料”轉(zhuǎn)載指數(shù)排名研究報告(2014)
- 李一氓文存(第二卷):存在集三編下冊
- 探索與實踐:博物館與口述歷史
- 春華集:中華書局員工文選(2019年)
- 圖書情報與圖書館服務(wù)探究
- 文書與檔案管理實務(wù)
- 黨校圖書館轉(zhuǎn)型發(fā)展實踐研究
- 且為繁華寄書香:高校圖書館閱讀推廣理論與實務(wù)
- 信息檢索
- 中國富布賴特學(xué)友會(籌)論文集(2013)