Skip to content

Commit 50e8707

Browse files
committed
Rollup merge of rust-lang#29617 - steveklabnik:gh29591, r=alexcrichton
Fixes rust-lang#29591
2 parents 6dbd250 + 586eb3d commit 50e8707

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

src/doc/trpl/strings.md

+23-3
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,29 @@ compiled program, and exists for the entire duration it runs. The `greeting`
2424
binding is a reference to this statically allocated string. String slices
2525
have a fixed size, and cannot be mutated.
2626

27-
A `String`, on the other hand, is a heap-allocated string. This string is
28-
growable, and is also guaranteed to be UTF-8. `String`s are commonly created by
29-
converting from a string slice using the `to_string` method.
27+
String literals can span multiple lines. There are two forms. The first will
28+
include the newline and the leading spaces:
29+
30+
```rust
31+
let s = "foo
32+
bar";
33+
34+
assert_eq!("foo\n bar", s);
35+
```
36+
37+
The second, with a `\`, does not trim the spaces:
38+
39+
```rust
40+
let s = "foo\
41+
bar";
42+
43+
assert_eq!("foobar", s);
44+
```
45+
46+
Rust has more than just `&str`s though. A `String`, is a heap-allocated string.
47+
This string is growable, and is also guaranteed to be UTF-8. `String`s are
48+
commonly created by converting from a string slice using the `to_string`
49+
method.
3050

3151
```rust
3252
let mut s = "Hello".to_string(); // mut s: String

0 commit comments

Comments
 (0)