Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions 06-flow/06-02-condition.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ let z = if let Some(y) = x {
}
else {
0
}
};
// z 值为 5

```
Expand All @@ -93,7 +93,7 @@ match x {
let z = match x {
Some(y) => y,
None => 0
}
};
```

设计这个语法的目的是,在条件判断的时候,直接做一次模式匹配,方便代码书写,使代码更紧凑。
Expand Down
2 changes: 1 addition & 1 deletion 07-type/07-02-compound-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

```rust
let y = (2, "hello world");
let x: (3, &str) = (3, "world hello");
let x: (i32, &str) = (3, "world hello");

// 然后呢,你能用很简单的方式去访问他们:

Expand Down
4 changes: 2 additions & 2 deletions 08-function/08-02-return_value.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
```rust
fn main() {
let a = 3;
println!("{}", inc(3));
println!("{}", inc(a));
}

fn inc(n: i32) -> i32 {
fn inc(n: i32) -> i32 {
n + 1
}
```
Expand Down
10 changes: 5 additions & 5 deletions 09-match/09-02-pattern.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# 模式
模式,是Rust另一个强大的语法。它可以被用在`let`和`match`表达式里面。相信大家应该还记得我们在[基础类型](../07-type/07-01-types.md)中提到的关于在let表达式中解构元组的例子,实际上这就是一个模式。
```rust
let tup = (0u9,1u8);
let tup = (0u8,1u8);
let (x, y) = tup;
```
而且我们需要知道的是,一个模式中如果出现了和前面的同名变量,则这个变量会在当前作用域里被模式中的值覆盖掉。比如:
Expand Down Expand Up @@ -73,7 +73,7 @@ match point {

## 忽略和内存管理

总结以下,我们遇到了两种不同的模式忽略的情况——`_`和`..`。这里要注意,模式匹配中被忽略的字段是不会被`move`的,而且实现`Copy`的也会优先被Copy而不是被`move`。
总结一下,我们遇到了两种不同的模式忽略的情况——`_`和`..`。这里要注意,模式匹配中被忽略的字段是不会被`move`的,而且实现`Copy`的也会优先被Copy而不是被`move`。

说的有点拗口,上代码:

Expand All @@ -87,7 +87,7 @@ let (x, s) = tuple;

let tuple = (5, String::from("five"));

/// 忽略String类型,而u32实现了Copy,则tuple不会被move
// 忽略String类型,而u32实现了Copy,则tuple不会被move
let (x, _) = tuple;

println!("Tuple is: {:?}", tuple);
Expand All @@ -113,8 +113,8 @@ let c = 'w';

match c {
'a' ... 'z' => println!("小写字母"),
'A' ... 'Z' => pringln!("大写字母"),
_ => pringln!("其他字符"),
'A' ... 'Z' => println!("大写字母"),
_ => println!("其他字符"),
}
```

Expand Down
2 changes: 1 addition & 1 deletion 12-ownership-system/12-01-ownership.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ struct Bar { //不可实现Copy特性
1. **通过derive让Rust编译器自动实现**

```rust
#derive(Copy, Clone)]
#[derive(Copy, Clone)]
struct Foo {
a: i32,
b: bool,
Expand Down