Skip to content

Commit 2b05fdb

Browse files
committed
Update 'Strings' chapter of the book
Fix #29823 by further explaining `&str` and pointing out the difference between `&str` and `&'static str`.
1 parent 4f5edf9 commit 2b05fdb

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/doc/trpl/strings.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ encoding of UTF-8 sequences. Additionally, unlike some systems languages,
1212
strings are not null-terminated and can contain null bytes.
1313

1414
Rust has two main types of strings: `&str` and `String`. Let’s talk about
15-
`&str` first. These are called ‘string slices’. String literals are of the type
16-
`&'static str`:
15+
`&str` first. These are called ‘string slices’. A string slice has a fixed
16+
size, and cannot be mutated. It is a reference to a sequence of UTF-8 bytes.
1717

1818
```rust
1919
let greeting = "Hello there."; // greeting: &'static str
2020
```
2121

22-
This string is statically allocated, meaning that it’s saved inside our
23-
compiled program, and exists for the entire duration it runs. The `greeting`
24-
binding is a reference to this statically allocated string. String slices
25-
have a fixed size, and cannot be mutated.
22+
`"Hello there."` is a string literal and its type is `&'static str`. String
23+
literal is a string slice that is statically allocated, meaning that it’s saved
24+
inside our compiled program, and exists for the entire duration it runs. The
25+
`greeting` binding is a reference to this statically allocated string.
2626

2727
String literals can span multiple lines. There are two forms. The first will
2828
include the newline and the leading spaces:

0 commit comments

Comments
 (0)