Skip to content

Commit

Permalink
deref
Browse files Browse the repository at this point in the history
  • Loading branch information
vhtmui committed Jan 19, 2025
1 parent 58866c4 commit f808726
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions docs/Rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -601,3 +601,9 @@ rust没有为基本类型提供隐式的自动类型转换,而是使用`as`进
* FnMut要求闭包是`mut`的。
* 如果闭包参数被注释了`FnOnce`,那它就可以捕获`不可变引用、可变引用和获取所有权`。因为`FnOnce`首先要求闭包获取所有权,如果实现闭包能获取所有权,那也能获取可变和不可变引用。相反,注释`Fn`的闭包则不能获取`不可变引用、可变引用和所有权`,因为它首先要求只捕获不可变引用。
* `move`关键词决定了闭包通过移动的`方式`捕获变量,但没有指定闭包实现的`trait`。闭包实现的`trait`由编译器根据闭包对捕获变量的使用方式自动推导,`Fn trait`只代表了闭包可以捕获变量的尽可能宽松的方式,这也说明,实现`Fn`trait的闭包并不一定没有捕获变量的所有权。

## 智能指针

### Deref解引用

解引用操作不会获取数据的所有权。

0 comments on commit f808726

Please sign in to comment.