- Rust in Action - Chapter 1: Reading Rust Installation and First Program Experience
- Book Overview
Cover
Read the contents of a book directly from the table of contents
-
- Chapter 1 Read Rust Installation
The first chapter introduces the language features of Rust, taking the helloworld program as an example to introduce the language features of Rust.
Overview This chapter provides some initial experience.
I will install rust later to experience it in practice.
https://www.rust-lang.org/zh-CN/
Reference: https://www.rust-lang.org/zh-CN/learn/get-started
Direct command line installation under WSL
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
Download the installation package directly under Windows
Open it directly after downloading
Press Enter to install by default
After the installation is complete, press Enter to complete the installation.
-
- First program
1. Enter the working directory cd %TMP%
2. Create a project cargo new helloworld
Print as follows
Created binary (application) `helloworld` package
- Enter the project directory cd helloworld
- Run the program cargo run
Print as follows
Compiling helloworld v0.1.0 (C:\Users\qinyunti\AppData\Local\Temp\helloworld)
Finished dev [unoptimized + debuginfo] target(s) in 1.08s
Running `target\debug\helloworld.exe`
Hello, world!
The whole process does not require writing a single line of code, and it can be said to be the fastest language to implement the helloworld program.
The ls command shows the following files
Cargo.lock Cargo.toml src target
tree /F View all files
C:\Users\qinyunti\AppData\Local\Temp\helloworld>tree /F
Folder PATH list for volume Windows-SSD
The volume serial number is 4AD2-DD24
C:.
│ .gitignore
│ Cargo.lock
│ Cargo.toml
│
├─src
│ main.rs
│
└─target
│ .rustc_info.json
│ CACHEDIR.TAG
│
└─debug
│ .cargo-lock
│ helloworld.d
│ helloworld.exe
│ helloworld.pdb
│
├─.fingerprint
│ └─helloworld-1a74b84bc6952173
│ bin-helloworld
│ bin-helloworld.json
│ dep-bin-helloworld
│ invoked.timestamp
│
├─build
├─deps
│ helloworld.d
│ helloworld.exe
│ helloworld.pdb
│
├─examples
└─incremental
└─helloworld-5zjffswzj0mv
│ s-guwobqpkw8-12adx41.lock
│
└─s-guwobqpkw8-12adx41-5w89ateoo09mo6pmr2xvlvj7z
163lw06jy9imt8ev.o
1wzoyque5cqlq6x0.o
2tif3lfmc7za466e.o
3hw4j8v765r39d13.o
3yaezxcbekx0rcwe.o
44p2yw96dxtbmzx7.o
dep-graph.bin
query-cache.bin
work-products.bin
The source code is src/main.rs
I use vscode to open the folder and edit the source code. The source code is as follows
There is only one main function, fn represents function, the entry is the main function, no parameters, println! ("Hello, world!") prints
Use the terminal directly in vscode and run
-
- Summarize
The Rust development environment is very simple to install, and running your first program is also very simple.
Download the code from the following address
https://box.lenovo.com/l/EnyvEo