Skip to content

Commit 40f5b30

Browse files
authored
Update solution to add using &* as well as as_str()
1 parent 2a62b91 commit 40f5b30

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/liballoc/string.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,15 @@ use boxed::Box;
183183
/// }
184184
/// ```
185185
///
186-
/// What would work in this case is changing the line
187-
/// `example_func(&example_string);` to
188-
/// `example_func(example_string.to_str());`. This works because we're doing
189-
/// the conversion explicitly, rather than relying on the implicit conversion.
186+
/// There are two options that would work instead. The first would be to
187+
/// change the line `example_func(&example_string);` to
188+
/// `example_func(example_string.as_str());`, using the method `as_str()`
189+
/// to explicitly extract the string slice containing the string. The second
190+
/// way changes `example_func(&example_string);` to
191+
/// `example_func(&*example_string);`. In this case we are dereferencing a
192+
/// `String` to a `str`, then referencing the `str` back to `&str`. The
193+
/// second way is more idiomatic, however both work to do the conversion
194+
/// explicitly rather than relying on the implicit conversion.
190195
///
191196
/// # Representation
192197
///

0 commit comments

Comments
 (0)