Skip to content

Commit ab953f6

Browse files
committed
---
yaml --- r: 192447 b: refs/heads/auto c: 68af512 h: refs/heads/master i: 192445: c74dac1 192443: 96786ae 192439: f14d8ee 192431: 31e17ff 192415: 188a291 192383: 6712da5 v: v3
1 parent d52c94f commit ab953f6

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1010
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1111
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1212
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
13-
refs/heads/auto: 1c25aecf675d731938951d048a45fb665105b441
13+
refs/heads/auto: 68af51212350094cd1533a7e7f37106241628731
1414
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1515
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1616
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/src/doc/trpl/more-strings.md

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Additionally, strings are not null-terminated and can contain null bytes.
1212

1313
Rust has two main types of strings: `&str` and `String`.
1414

15-
# &str
15+
# `&str`
1616

1717
The first kind is a `&str`. This is pronounced a 'string slice'.
1818
String literals are of the type `&str`:
@@ -36,7 +36,36 @@ Like vector slices, string slices are simply a pointer plus a length. This
3636
means that they're a 'view' into an already-allocated string, such as a
3737
string literal or a `String`.
3838

39-
# String
39+
## `str`
40+
41+
You may occasionally see references to a `str` type, without the `&`. While
42+
this type does exist, it’s not something you want to use yourself. Sometimes,
43+
people confuse `str` for `String`, and write this:
44+
45+
```rust
46+
struct S {
47+
s: str,
48+
}
49+
```
50+
51+
This leads to ugly errors:
52+
53+
```text
54+
error: the trait `core::marker::Sized` is not implemented for the type `str` [E0277]
55+
note: `str` does not have a constant size known at compile-time
56+
```
57+
58+
Instead, this `struct` should be
59+
60+
```rust
61+
struct S {
62+
s: String,
63+
}
64+
```
65+
66+
So let’s talk about `String`s.
67+
68+
# `String`
4069

4170
A `String` is a heap-allocated string. This string is growable, and is
4271
also guaranteed to be UTF-8. `String`s are commonly created by

0 commit comments

Comments
 (0)