88
99- 创建一个 Doing 目录和 helloworld.rs 文件
1010
11- > ps: mkdir ~ /Doing
12- > ps: cd ~ /Doing
13- > ps: notepad helloworld.rs # 作者偏向于使用 sublime 作为编辑器
14- > ps: subl helloworld.rs # 本章以后使用 subl 代替 notepad
11+ > ps: mkdir ~ /Doing
12+ > ps: cd ~ /Doing
13+ > ps: notepad helloworld.rs # 作者偏向于使用 sublime 作为编辑器
14+ > ps: subl helloworld.rs # 本章以后使用 subl 代替 notepad
1515
1616注意这里用的后缀名是.rs,一般编程语言的代码文件都有惯用的后缀名,比如:
1717 C语言是.c,java是.java,python是.py等等,** 请务必记住Rust语言的惯用后缀名是.rs** (虽然用别的后缀名也能通过rustc的编译)。
@@ -26,13 +26,13 @@ fn main() {
2626
2727- 编译 helloworld.rs 文件
2828
29- > ps: rustc helloworld.rs
30- > ps: rustc helloworld.rs -O # 也可以选择优化编译
29+ > ps: rustc helloworld.rs
30+ > ps: rustc helloworld.rs -O # 也可以选择优化编译
3131
3232- 运行程序
3333
34- > ps: ./helloworld.exe # windows 平台下需要加 .exe 后缀
35- > Hello World!
34+ > ps: ./helloworld.exe # windows 平台下需要加 .exe 后缀
35+ > Hello World!
3636
3737没有` ps: ` 前缀的表示为控制台打印输出。
3838
@@ -53,20 +53,20 @@ fn main() {
5353
5454- 查看目录结构
5555
56- > ps: tree # win10 powershell 自带有 tree 查看文件目录结构的功能
57- > └─hellorust
56+ > ps: tree # win10 powershell 自带有 tree 查看文件目录结构的功能
57+ > └─hellorust
5858> ----└─src
5959
6060这里显示的目录结构,在hellorust目录下有 src 文件夹和 Cargo.toml 文件,同时这个目录会初始化为 git 项目
6161
6262- 查看Cargo.toml文件
6363
64- > ps: cat Cargo.toml
65- > [ package]
66- name = "hellorust"
67- version = "0.1."
64+ > ps: cat Cargo.toml
65+ > [ package]
66+ name = "hellorust"
67+ version = "0.1."
6868authors = [ "YourName <YourEmail >"]
69- > [ dependencies]
69+ > [ dependencies]
7070
7171- 编辑src目录下的main.rs文件
7272
@@ -90,9 +90,9 @@ fn main() {
9090
9191- 编译和运行
9292
93- > ps: cargo build
94- > ps: cargo build --release # 这个属于优化编译
95- > ps: ./target/debug/hellorust.exe
96- > ps: ./target/release/hellorust.exe # 如果前面是优化编译,则这样运行
97- > ps: cargo run # 编译和运行合在一起
98- > ps: cargo run --release # 同上,区别是是优化编译的
93+ > ps: cargo build
94+ > ps: cargo build --release # 这个属于优化编译
95+ > ps: ./target/debug/hellorust.exe
96+ > ps: ./target/release/hellorust.exe # 如果前面是优化编译,则这样运行
97+ > ps: cargo run # 编译和运行合在一起
98+ > ps: cargo run --release # 同上,区别是是优化编译的
0 commit comments