Skip to content

Commit

Permalink
Update ch05-02-example-structs.md (#115)
Browse files Browse the repository at this point in the history
Co-authored-by: YangQi <2419731931@qq.com>
  • Loading branch information
focksor and YangFong committed Dec 19, 2022
1 parent e3c8c6a commit c91859d
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/ch05-02-example-structs.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,11 @@ Rust **确实**包含了打印出调试信息的功能,不过我们必须为
{{#include ../listings/ch05-using-structs-to-structure-related-data/output-only-02-pretty-debug/output.txt}}
```

另一种使用 `Debug` 格式打印数值的方法是使用 [`dbg!`][dbg]<!-- ignore -->`dbg!` 宏接收一个表达式的所有权,打印出代码中调用 `dbg!` 宏时所在的文件和行号,以及该表达式的结果值,并返回该值的所有权。调用 `dbg!` 宏会打印到标准错误控制台流(`stderr`),而不是 `println!`,后者会打印到标准输出控制台流(`stdout`)。我们将在[第 12 章 “将错误信息写入标准错误而不是标准输出” 一节][err]<!-- ignore -->中更多地讨论 `stderr``stdout`。下面是一个例子,我们对分配给 `width` 字段的值以及 `rect1` 中整个结构的值感兴趣。
另一种使用 `Debug` 格式打印数值的方法是使用 [`dbg!`][dbg]<!-- ignore -->`dbg!` 宏接收一个表达式的所有权,打印出代码中调用 `dbg!` 宏时所在的文件和行号,以及该表达式的结果值,并返回该值的所有权。

> 注释:与 `println!` 宏打印到标准输出控制流(`stdout`)不同,调用 `dbg!` 宏会打印到标准错误控制流(`stderr`)。我们将在[第 12 章 “将错误信息输出到标准错误而不是标准输出” 一节][err]<!-- ignore -->中更多地讨论 `stderr``stdout`
下面是一个例子,我们对分配给 `width` 字段的值以及 `rect1` 中整个结构的值感兴趣:

```rust
{{#rustdoc_include ../listings/ch05-using-structs-to-structure-related-data/no-listing-05-dbg-macro/src/main.rs}}
Expand Down

0 comments on commit c91859d

Please sign in to comment.