Skip to content

Commit

Permalink
Update archives.
Browse files Browse the repository at this point in the history
  • Loading branch information
poneding committed Nov 1, 2024
1 parent 1c51970 commit 1b3ba8b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions content/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,3 +259,4 @@
- [Cargo 管理工具](rust/02-cargo.md)
- [VSCode 调试](rust/03-vscode-debugging.md)
- [Rust WASM 编程](rust/04-wasm-programming.md)
- [String 还是 &str](rust/string-&str.md)
2 changes: 2 additions & 0 deletions content/rust/04-wasm-programming.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,5 @@ wasm-pack build --scope [npm-username]

---
[« VSCode 调试](03-vscode-debugging.md)

[» String 还是 &str](string-&str.md)
2 changes: 2 additions & 0 deletions content/rust/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@
[VSCode 调试](03-vscode-debugging.md)

[Rust WASM 编程](04-wasm-programming.md)

[String 还是 &str](string-&str.md)
14 changes: 14 additions & 0 deletions content/rust/string-&str.md
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)

0 comments on commit 1b3ba8b

Please sign in to comment.