Skip to content

优化 《 使用 + 或者 += 连接字符串 》 小节内容#1610

Open
Creat55 wants to merge 1 commit into
sunface:mainfrom
Creat55:patch-1
Open

优化 《 使用 + 或者 += 连接字符串 》 小节内容#1610
Creat55 wants to merge 1 commit into
sunface:mainfrom
Creat55:patch-1

Conversation

@Creat55

@Creat55 Creat55 commented Jun 16, 2026

Copy link
Copy Markdown

原文对+左右所有权的解释比较模糊,本次修订:

  • 直接展示 fn add(mut self, other: &str) -> String 签名,并解释其所有权含义。
  • 明确左侧必须是 String(转移所有权,不能使用引用),右侧必须是 &str(不可变借用)。
  • 补充说明 += 等价于 s = s + &str,因此左侧变量必须声明为 mut。

原文对+左右所有权的解释比较模糊,本次修订:
- 直接展示 `fn add(mut self, other: &str) -> String` 签名,并解释其所有权含义。
- 明确左侧必须是 String(转移所有权,不能使用引用),右侧必须是 &str(不可变借用)。
- 补充说明 `+=` 等价于 `s = s + &str`,因此左侧变量必须声明为 mut。
- 保留全部原有示例,仅调整周边解释,使概念更准确、教学更清晰。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant