Update solution to add using &*
as well as as_str()
This commit is contained in:
parent
2a62b91343
commit
40f5b308bc
1 changed files with 9 additions and 4 deletions
|
@ -183,10 +183,15 @@ use boxed::Box;
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// What would work in this case is changing the line
|
/// There are two options that would work instead. The first would be to
|
||||||
/// `example_func(&example_string);` to
|
/// change the line `example_func(&example_string);` to
|
||||||
/// `example_func(example_string.to_str());`. This works because we're doing
|
/// `example_func(example_string.as_str());`, using the method `as_str()`
|
||||||
/// the conversion explicitly, rather than relying on the implicit conversion.
|
/// 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
|
/// # Representation
|
||||||
///
|
///
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue