Skip to content

Commit c7d5354

Browse files
committed
Rollup merge of #23181 - steveklabnik:gh22637, r=alexcrichton
Fixes #22637
2 parents d1ac69c + ce223a6 commit c7d5354

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/doc/trpl/more-strings.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,18 @@ This will print:
278278

279279
Many more bytes than graphemes!
280280

281-
# Other Documentation
281+
# `Deref` coercions
282282

283-
* [the `&str` API documentation](../std/str/index.html)
284-
* [the `String` API documentation](../std/string/index.html)
283+
References to `String`s will automatically coerce into `&str`s. Like this:
284+
285+
```
286+
fn hello(s: &str) {
287+
println!("Hello, {}!", s);
288+
}
289+
290+
let slice = "Steve";
291+
let string = "Steve".to_string();
292+
293+
hello(slice);
294+
hello(&string);
295+
```

0 commit comments

Comments
 (0)