Skip to content

Commit

Permalink
update ch04-02 close #822
Browse files Browse the repository at this point in the history
  • Loading branch information
KaiserY committed Nov 3, 2024
1 parent 4011c30 commit 8cb590d
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/ch04-02-references-and-borrowing.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
{{#rustdoc_include ../listings/ch04-understanding-ownership/no-listing-07-reference/src/main.rs:all}}
```

首先,注意变量声明和函数返回值中的所有元组代码都消失了。其次,注意我们传递 `&s1``calculate_length`,同时在函数定义中,我们获取 `&String` 而不是 `String`。这些 & 符号就是 **引用**,它们允许你使用值但不获取其所有权。图 4-5 展示了一张示意图。
首先,注意变量声明和函数返回值中的所有元组代码都消失了。其次,注意我们传递 `&s1``calculate_length`,同时在函数定义中,我们获取 `&String` 而不是 `String`。这些 & 符号就是 **引用**,它们允许你使用值但不获取其所有权。图 4-6 展示了一张示意图。

<img alt="Three tables: the table for s contains only a pointer to the table
for s1. The table for s1 contains the stack data for s1 and points to the
string data on the heap." src="img/trpl04-05.svg" class="center" />
string data on the heap." src="img/trpl04-06.svg" class="center" />

<span class="caption">图 4-5`&String s` 指向 `String s1` 示意图</span>
<span class="caption">图 4-6`&String s` 指向 `String s1` 示意图</span>

> 注意:与使用 `&` 引用相反的操作是 **解引用***dereferencing*),它使用解引用运算符,`*`。我们将会在第八章遇到一些解引用运算符,并在第十五章详细讨论解引用。
Expand Down

0 comments on commit 8cb590d

Please sign in to comment.