Skip to content

fix typo #580

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
10 changes: 5 additions & 5 deletions ownership-system/borrowing_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,21 @@ fn main() {
}
```

###借用与引用的区别
### 借用与引用的区别

借用与引用是一种相辅相成的关系,若B是对A的引用,也可称之为B借用了A。

很相近对吧,但是借用一词本意为要归还。所以在Rust用引用时,一定要注意应该在何处何时正确的“归回”借用/引用。
最后面的“高级”小节会详细举例。

###规则
### 规则

1. 同一作用域,特定数据最多只有一个可变借用(&mut T),或者2。
2. 同一作用域,特定数据可有0个或多个不可变借用(&T),但不能有任何可变借用。
3. 借用在离开作用域后释放。
4. 在可变借用释放前不可访问源变量。

###可变性
### 可变性
Borrowing也分“不可变借用”(默认,**&T**)和“可变借用”(**&mut T**)。

顾名思义,“不可变借用”是只读的,不可更新被引用的内容。
Expand Down Expand Up @@ -83,7 +83,7 @@ fn main() {
} //y在此处销毁
```

###高级例子
### 高级例子
下面的复杂例子,进行了详细的注释,即使看不懂也没关系,可以在完成Lifetimes(生命周期)的学习后再仔细思考本例子。

```rust
Expand Down Expand Up @@ -113,7 +113,7 @@ fn main() {
}
```

####总结
#### 总结
1. 借用不改变内存的所有者(Owner),借用只是对源内存的临时引用。
2. 在借用周期内,借用方可以读写这块内存,所有者被禁止读写内存;且所有者保证在有“借用”存在的情况下,不会释放或转移内存。
3. 失去所有权的变量不可以被借用(访问)。
Expand Down