-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
19 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,5 @@ | |
[VSCode 调试](03-vscode-debugging.md) | ||
|
||
[Rust WASM 编程](04-wasm-programming.md) | ||
|
||
[String 还是 &str](string-&str.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[🏠 首页](../_index.md) / [Rust 编程](_index.md) / String 还是 &str | ||
|
||
# String 还是 &str | ||
|
||
好用的规则: | ||
|
||
1. 始终在结构体中使用 `String`; | ||
2. 函数入参使用 `&str`,函数出参使用 `String`; | ||
3. 如果函数出参来源于入参,并且函数中没有改变入参,那么出参使用 `&str`。 | ||
|
||
遵循以上的规则,大部分场景你将很好的避开 `String &str` 使用困难,即使有问题,编译器会告知你问题所在。 | ||
|
||
--- | ||
[« Rust WASM 编程](04-wasm-programming.md) |