Skip to content

Commit ce223a6

Browse files
committed
Mention deref coercions in the String guide.
Fixes #22637
1 parent b2f09c1 commit ce223a6

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)