Skip to content

Commit 6ce63fb

Browse files
committed
Add note on str being an unsized type in strings section of book.
1 parent f1578d3 commit 6ce63fb

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/doc/book/strings.md

+6
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ let s = "foo\
4444
assert_eq!("foobar", s);
4545
```
4646

47+
Note that you normally cannot access a `str` directly, but only through a `&str`
48+
reference. This is because `str` is an unsized type which requires additional
49+
runtime information to be usable. For more information see the chapter on
50+
[unsized types][ut].
51+
4752
Rust has more than only `&str`s though. A `String` is a heap-allocated string.
4853
This string is growable, and is also guaranteed to be UTF-8. `String`s are
4954
commonly created by converting from a string slice using the `to_string`
@@ -185,5 +190,6 @@ let hello_world = hello + &world;
185190
This is because `&String` can automatically coerce to a `&str`. This is a
186191
feature called ‘[`Deref` coercions][dc]’.
187192

193+
[ut]: unsized-types.html
188194
[dc]: deref-coercions.html
189195
[connect]: ../std/net/struct.TcpStream.html#method.connect

0 commit comments

Comments
 (0)