diff options
| author | Natalie Boehm <nmb56@pitt.edu> | 2017-08-08 14:57:34 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-08-08 14:57:34 -0400 |
| commit | 40f5b308bcf8024cd17b982d543695873bc9dd53 (patch) | |
| tree | 6004163154b6ff829e5a9e39f7583c408f36b10a /src/liballoc | |
| parent | 2a62b91343b4de94b6cfe401e8ad9bc0414f245f (diff) | |
| download | rust-40f5b308bcf8024cd17b982d543695873bc9dd53.tar.gz rust-40f5b308bcf8024cd17b982d543695873bc9dd53.zip | |
Update solution to add using `&*` as well as `as_str()`
Diffstat (limited to 'src/liballoc')
| -rw-r--r-- | src/liballoc/string.rs | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/liballoc/string.rs b/src/liballoc/string.rs index 89f3ddcd18a..a1f0b4f0de1 100644 --- a/src/liballoc/string.rs +++ b/src/liballoc/string.rs @@ -183,10 +183,15 @@ use boxed::Box; /// } /// ``` /// -/// What would work in this case is changing the line -/// `example_func(&example_string);` to -/// `example_func(example_string.to_str());`. This works because we're doing -/// the conversion explicitly, rather than relying on the implicit conversion. +/// There are two options that would work instead. The first would be to +/// change the line `example_func(&example_string);` to +/// `example_func(example_string.as_str());`, using the method `as_str()` +/// to explicitly extract the string slice containing the string. The second +/// way changes `example_func(&example_string);` to +/// `example_func(&*example_string);`. In this case we are dereferencing a +/// `String` to a `str`, then referencing the `str` back to `&str`. The +/// second way is more idiomatic, however both work to do the conversion +/// explicitly rather than relying on the implicit conversion. /// /// # Representation /// |
