mirror of
https://github.com/rust-lang/book.git
synced 2026-11-30 19:54:34 -06:00
Move this comment to the first time we use push_str()
This commit is contained in:
@@ -77,7 +77,7 @@ This kind of string can be mutated:
|
||||
```rust
|
||||
let mut s = String::from("hello");
|
||||
|
||||
s.push_str(", world!");
|
||||
s.push_str(", world!"); // push_str() appends a literal to a String
|
||||
|
||||
println!("{}", s); // This will print `hello, world!`
|
||||
```
|
||||
|
||||
@@ -100,7 +100,7 @@ fn main() {
|
||||
}
|
||||
|
||||
fn change(some_string: &String) {
|
||||
some_string.push_str(", world"); // push_str() appends a literal to a String
|
||||
some_string.push_str(", world");
|
||||
}
|
||||
```
|
||||
|
||||
@@ -108,7 +108,7 @@ Here’s the error:
|
||||
|
||||
```text
|
||||
8:16 error: cannot borrow immutable borrowed content `*some_string` as mutable
|
||||
some_string.push_str(", world"); // push_str() appends a literal to a String
|
||||
some_string.push_str(", world");
|
||||
^~~~~~~~~~~
|
||||
```
|
||||
|
||||
@@ -127,7 +127,7 @@ fn main() {
|
||||
}
|
||||
|
||||
fn change(some_string: &mut String) {
|
||||
some_string.push_str(", world"); // push_str() appends a literal to a String
|
||||
some_string.push_str(", world");
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user