Skip to content
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

"Diverge function" to "diverging functions" #1496

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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 src/basic/base-type/char-bool.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ fn main() {

使用布尔类型的场景主要在于流程控制,例如上述代码的中的 `if` 就是其中之一。

## 单元类型
## 单元类型(unit)

单元类型就是 `()` ,对,你没看错,就是 `()` ,唯一的值也是 `()` ,一些读者读到这里可能就不愿意了,你也太敷衍了吧,管这叫类型?

只能说,再不起眼的东西,都有其用途,在目前为止的学习过程中,大家已经看到过很多次 `fn main()` 函数的使用吧?那么这个函数返回什么呢?

没错, `main` 函数就返回这个单元类型 `()`,你不能说 `main` 函数无返回值,因为没有返回值的函数在 Rust 中是有单独的定义的:`发散函数( diverge function )`,顾名思义,无法收敛的函数。
没错, `main` 函数就返回这个单元类型 `()`,你不能说 `main` 函数无返回值,因为没有返回值的函数在 Rust 中是有单独的定义的:`发散函数( diverging functions )`,顾名思义,无法收敛的函数。

例如常见的 `println!()` 的返回值也是单元类型 `()`。

Expand Down
2 changes: 1 addition & 1 deletion src/basic/base-type/function.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ error[E0308]: mismatched types // 类型不匹配

##### 永不返回的发散函数 `!`

当用 `!` 作函数返回类型的时候,表示该函数永不返回( diverge function ),特别的,这种语法往往用做会导致程序崩溃的函数:
当用 `!` 作函数返回类型的时候,表示该函数永不返回( diverging functions ),特别的,这种语法往往用做会导致程序崩溃的函数:

```rust
fn dead_end() -> ! {
Expand Down