Skip to content

Commit e2565ff

Browse files
author
WaySLOG
committed
Merge pull request #377 from lucklove/master
说明Copy和所有权的关系
2 parents 439948f + ae75c20 commit e2565ff

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

quickstart/function-method.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,13 @@ let plus_num = |x: i32| x + num;
4141
let mut num = 5;
4242

4343
{
44-
let mut add_num = move |x: i32| num += x;
44+
let mut add_num = move |x: i32| num += x; // 闭包通过move获取了num的所有权
4545

4646
add_num(5);
4747
}
4848

49+
// 下面的num在被move之后还能继续使用是因为其实现了Copy特性
50+
// 具体可见所有权(Owership)章节
4951
assert_eq!(5, num);
5052
```
5153
## 高阶函数

0 commit comments

Comments
 (0)