From 69189b361ce577271dca2169caa985f2bd0b8822 Mon Sep 17 00:00:00 2001 From: Lion Guo Date: Sat, 2 Apr 2022 07:30:32 +0000 Subject: [PATCH 01/34] Remove wrong file name, which block checkout on Win OS --- src/https:/github.com | 1 - 1 file changed, 1 deletion(-) delete mode 100644 src/https:/github.com diff --git a/src/https:/github.com b/src/https:/github.com deleted file mode 100644 index 83c831f0..00000000 --- a/src/https:/github.com +++ /dev/null @@ -1 +0,0 @@ -# test From 8757e1cdfa6b1f0cee1f1a9a8f24153f372b0f61 Mon Sep 17 00:00:00 2001 From: themanforfree <56149350+themanforfree@users.noreply.github.com> Date: Sat, 2 Apr 2022 23:39:56 +0800 Subject: [PATCH 02/34] fix wrong url --- src/first-try/hello-world.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/first-try/hello-world.md b/src/first-try/hello-world.md index a14910fd..9121320e 100644 --- a/src/first-try/hello-world.md +++ b/src/first-try/hello-world.md @@ -4,7 +4,7 @@ ## 多国语言的"世界,你好" -还记得大明湖畔等你的 [VSCode IDE](https://course.rs/first-try/editor.md) 和通过 `Cargo` 创建的 [世界,你好](https://course.rs/first-try/cargo.html) 工程吗? +还记得大明湖畔等你的 [VSCode IDE](https://course.rs/first-try/editor.html) 和通过 `Cargo` 创建的 [世界,你好](https://course.rs/first-try/cargo.html) 工程吗? 现在使用 VSCode 打开 [上一节](https://course.rs/first-try/cargo.html) 中创建的 `world_hello` 工程,然后进入 `main.rs` 文件。(此文件是当前 Rust 工程的入口文件,和其它语言几无区别。) From bdaedb283616124c07c9eece528eb8cdc1fa4447 Mon Sep 17 00:00:00 2001 From: Allan Downey Date: Sun, 3 Apr 2022 10:09:37 +0800 Subject: [PATCH 03/34] update(index-list): add flow-control --- src/index-list.md | 48 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/src/index-list.md b/src/index-list.md index 11dd59f1..f50acd14 100644 --- a/src/index-list.md +++ b/src/index-list.md @@ -26,6 +26,7 @@ | [&] | 引用 | 常规引用是一个指针类型,指向了对象存储的内存地址 | | [\*] | 解引用 | 解出引用所指向的值 | | [@] | 变量绑定 | 为一个字段绑定另外一个变量 | +| `_` | | 忽略该值或者类型 | | ['a: 'b] | 生命周期约束 | 用来说明两个生命周期的长短 | | [{:?}] {:#?} | 打印结构体信息 | 使用 `#[derive(Debug)]` 派生实现 `Debug` 特征 | | A | | AIntroduction | @@ -63,12 +64,14 @@ | [变量作用域] | 所有权 | 作用域是一个变量在程序中有效的范围 | | [表达式] | | 进行求值,结尾无 `;`,有返回值 | | [bool 布尔] | 布尔类型 | `true` `false`,占用 1 字节 | +| [break] | 循环控制 | 直接跳出当前整个循环 | | B | KWB | BIntroduction | [变量遮蔽]: https://course.rs/basic/variable.html#变量遮蔽shadowing [变量作用域]: https://course.rs/basic/ownership/ownership.html#变量作用域 [bool 布尔]: https://course.rs/basic/base-type/char-bool.html#布尔bool [表达式]: https://course.rs/basic/base-type/statement-expression.html#表达式 +[break]: https://course.rs/basic/flow-control.html#break [back](#head) @@ -79,6 +82,7 @@ | [char 字符] | 字符类型 | 使用 `''` 表示,所有的 Unicode 值 | | [const 常量] | constant | `const MAX_POINTS: u32 = 100_000;` | | [Copy 拷贝] | 浅拷贝 | 任何基本类型的组合可以 `Copy`,不需要分配内存或某种形式资源的类型是可以 `Copy` 的。 | +| [continue] | 循环控制 | 跳过当前当次的循环,开始下次的循环 | | [Clone 克隆] | 深拷贝 | 需要复制堆上的数据时,可以使用 `.clone()` 方法 | | C | KWC | CIntroduction | @@ -86,6 +90,7 @@ [const 常量]: https://course.rs/basic/variable.html#变量和常量之间的差异 [copy 拷贝]: https://course.rs/basic/ownership/ownership.html#拷贝浅拷贝 [clone 克隆]: https://course.rs/basic/ownership/ownership.html#克隆深拷贝 +[continue]: https://course.rs/basic/flow-control.html#continue [back](#head) @@ -110,12 +115,14 @@ ## F -| 名称 | 关键字 | 简介 | -| -------- | -------- | ------------------------ | -| [浮点数] | 数值类型 | `f32`
`f64`(默认类型) | -| F | KWF | FIntroduction | +| 名称 | 关键字 | 简介 | +| ---------- | -------- | ---------------------------- | +| [浮点数] | 数值类型 | `f32`
`f64`(默认类型) | +| [for 循环] | 循环控制 | `for item in &collection {}` | +| F | KWF | FIntroduction | [浮点数]: https://course.rs/basic/base-type/numbers.html#浮点类型 +[for 循环]: https://course.rs/basic/flow-control.html#for-循环 [back](#head) @@ -140,9 +147,14 @@ ## I -| 名称 | 关键字 | 简介 | -| ---- | ------ | ------------- | -| I | KWI | IIntroduction | +| 名称 | 关键字 | 简介 | +| --------- | -------- | -------------------------- | +| [if else] | 流程控制 | 根据条件执行不同的代码分支 | +| [else if] | 流程控制 | 处理多重条件 | +| I | KWI | IIntroduction | + +[if else]: https://course.rs/basic/flow-control.html#使用-if-来做分支控制 +[else if]: https://course.rs/basic/flow-control.html#使用-else-if-来处理多重条件 [back](#head) @@ -164,14 +176,17 @@ ## L -| 名称 | 关键字 | 简介 | -| --------- | -------- | ----------------------------- | -| [let] | 变量绑定 | `let x : u32 = 5;` | -| [let mut] | 可变变量 | `let mut x : u32 = 5; x = 9;` | -| L | KWL | LIntroduction | +| 名称 | 关键字 | 简介 | +| ----------- | -------- | ------------------------------ | +| [let] | 变量绑定 | `let x : u32 = 5;` | +| [let mut] | 可变变量 | `let mut x : u32 = 5; x = 9;` | +| [loop 循环] | 循环控制 | 无限循环,注意要配合 [`break`] | +| L | KWL | LIntroduction | [let]: https://course.rs/basic/variable.html#变量绑定 [let mut]: https://course.rs/basic/variable.html#变量可变性 +[`break`]: https://course.rs/basic/flow-control.html#break +[loop 循环]: https://course.rs/basic/flow-control.html#loop-循环 [back](#head) @@ -287,9 +302,12 @@ ## W -| 名称 | 关键字 | 简介 | -| ---- | ------ | ------------- | -| W | KWW | WIntroduction | +| 名称 | 关键字 | 简介 | +| ------------ | -------- | ------------------------------------------------------ | +| [while 循环] | 循环控制 | 当条件为 `true` 时,继续循环,条件为 `false`,跳出循环 | +| W | KWW | WIntroduction | + +[while 循环]: https://course.rs/basic/flow-control.html#while-循环 [back](#head) From 7c397856c099f0edc3c62f78065930635f58b5e2 Mon Sep 17 00:00:00 2001 From: Allan Downey Date: Sun, 3 Apr 2022 10:25:26 +0800 Subject: [PATCH 04/34] Update: unified format --- src/basic/flow-control.md | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/src/basic/flow-control.md b/src/basic/flow-control.md index e5f24560..d17544bc 100644 --- a/src/basic/flow-control.md +++ b/src/basic/flow-control.md @@ -6,7 +6,7 @@ ## 使用 if 来做分支控制 -> if else 无处不在 - 鲁迅 +> if else 无处不在 -- 鲁迅 但凡你能找到一门编程语言没有 `if else`,那么一定更要反馈给鲁迅,反正不是我说的:) 总之,只要你拥有其它语言的编程经验,就一定会有以下认知:`if else` **表达式**根据条件执行不同的代码分支: @@ -56,7 +56,7 @@ error[E0308]: if and else have incompatible types found type `&str` ``` -#### 使用 else if 来处理多重条件 +## 使用 else if 来处理多重条件 可以将 `else if` 与 `if`、`else` 组合在一起实现更复杂的条件分支判断: @@ -82,20 +82,20 @@ fn main() { 如果代码中有大量的 `else if ` 会让代码变得极其丑陋,不过不用担心,下一章的 `match` 专门用以解决多分支模式匹配的问题。 -## 循环控制 +# 循环控制 循环无处不在,上到数钱,下到数年,你能想象的很多场景都存在循环,因此它也是流程控制中最重要的组成部分之一。 在 Rust 语言中有三种循环方式:`for`、`while` 和 `loop`,其中 `for` 循环是 Rust 循环王冠上的明珠。 -#### for 循环 +## for 循环 `for` 循环是 Rust 的大杀器: ```rust fn main() { for i in 1..=5 { - println!("{}",i); + println!("{}", i); } } ``` @@ -140,10 +140,10 @@ for item in &mut collection { ```rust fn main() { - let a = [4,3,2,1]; + let a = [4, 3, 2, 1]; // `.iter()` 方法把 `a` 数组变成一个迭代器 - for (i,v) in a.iter().enumerate() { - println!("第{}个元素是{}",i+1,v); + for (i, v) in a.iter().enumerate() { + println!("第{}个元素是{}", i + 1, v); } } ``` @@ -183,7 +183,7 @@ for item in collection { 由于 `for` 循环无需任何条件限制,也不需要通过索引来访问,因此是最安全也是最常用的,通过与下面的 `while` 的对比,我们能看到为什么 `for` 会更加安全。 -#### `continue` +## `continue` 使用 `continue` 可以跳过当前当次的循环,开始下次的循环: @@ -192,7 +192,7 @@ for item in collection { if i == 2 { continue; } - println!("{}",i); + println!("{}", i); } ``` @@ -203,7 +203,7 @@ for item in collection { 3 ``` -#### `break` +## `break` 使用 `break` 可以直接跳出当前整个循环: @@ -212,7 +212,7 @@ for item in collection { if i == 2 { break; } - println!("{}",i); + println!("{}", i); } ``` @@ -222,7 +222,7 @@ for item in collection { 1 ``` -#### while 循环 +## while 循环 如果你需要一个条件来循环,当该条件为 `true` 时,继续循环,条件为 `false`,跳出循环,那么 `while` 就非常适用: @@ -262,7 +262,7 @@ fn main() { if n > 5 { break } - println!("{}",n); + println!("{}", n); n+=1; } @@ -317,7 +317,7 @@ fn main() { 可以看出,`for` 并不会使用索引去访问数组,因此更安全也更简洁,同时避免 `运行时的边界检查`,性能更高。 -#### loop 循环 +## loop 循环 对于循环而言,`loop` 循环毋庸置疑,是适用面最高的,它可以适用于所有循环场景(虽然能用,但是在很多场景下, `for` 和 `while` 才是最优选择),因为 `loop` 就是一个简单的无限循环,你可以在内部实现逻辑通过 `break` 关键字来控制循环何时结束。 @@ -368,8 +368,6 @@ fn main() { - **break 可以单独使用,也可以带一个返回值**,有些类似 `return` - **loop 是一个表达式**,因此可以返回一个值 - ## 课后练习 > [Rust By Practice](https://zh.practice.rs/flow-control.html),支持代码在线编辑和运行,并提供详细的[习题解答](https://github.com/sunface/rust-by-practice)。 - From 93e73e68669f8e5cbccbfac71c94000f3fb8c9a0 Mon Sep 17 00:00:00 2001 From: sunface Date: Sun, 3 Apr 2022 22:56:46 +0800 Subject: [PATCH 05/34] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=AB=A0=E8=8A=82=20[C?= =?UTF-8?q?ookbook=20-=20=E7=BA=BF=E7=A8=8B]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/SUMMARY.md | 9 +- src/cookbook/cocurrency/threads.md | 336 +++++++++++++++++++++++++++++ src/cookbook/compression/intro.md | 3 - 3 files changed, 342 insertions(+), 6 deletions(-) create mode 100644 src/cookbook/cocurrency/threads.md delete mode 100644 src/cookbook/compression/intro.md diff --git a/src/SUMMARY.md b/src/SUMMARY.md index 89e1ba93..41a95322 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -270,9 +270,12 @@ - [命令行]() - [参数解析](cookbook/cmd/parsing.md) - [终端输出格式化](cookbook/cmd/ansi.md) - - [压缩](cookbook/compression/intro.md) + - [压缩]() - [使用.tar包](cookbook/compression/tar.md) - - [配置文件解析 todo](cookbook/config.md) + - [并发]() + - [线程](cookbook/cocurrency/threads.md) + +