diff options
| author | Alejandro Wainzinger <aikawarazuni@gmail.com> | 2016-03-25 23:25:40 +0900 |
|---|---|---|
| committer | Alejandro Wainzinger <aikawarazuni@gmail.com> | 2016-03-25 23:25:40 +0900 |
| commit | 6ce63fb3f1bf37004868f79beacb180283c0750e (patch) | |
| tree | a7fc13ec45bc2e20c2b770cb8586ac040cf86705 | |
| parent | f1578d37dc844ffeefcabc30960784082c3c54fa (diff) | |
Add note on `str` being an unsized type in strings section of book.
| -rw-r--r-- | src/doc/book/strings.md | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/doc/book/strings.md b/src/doc/book/strings.md index 5ed1f3de062..f5ebceedd36 100644 --- a/src/doc/book/strings.md +++ b/src/doc/book/strings.md @@ -44,6 +44,11 @@ let s = "foo\ assert_eq!("foobar", s); ``` +Note that you normally cannot access a `str` directly, but only through a `&str` +reference. This is because `str` is an unsized type which requires additional +runtime information to be usable. For more information see the chapter on +[unsized types][ut]. + Rust has more than only `&str`s though. A `String` is a heap-allocated string. This string is growable, and is also guaranteed to be UTF-8. `String`s are commonly created by converting from a string slice using the `to_string` @@ -185,5 +190,6 @@ let hello_world = hello + &world; This is because `&String` can automatically coerce to a `&str`. This is a feature called ‘[`Deref` coercions][dc]’. +[ut]: unsized-types.html [dc]: deref-coercions.html [connect]: ../std/net/struct.TcpStream.html#method.connect |
