Code examples in step 2.4 do not compile
PalaBeaveR opened this issue · comments
PalaBeaveR commented
Summary
This code example produces compiler errors because it cannot find the AsRef
and AsMut
derive macros since they are not available in the standard library and are instead provided by the derive_more
crate.
In this code example the compiler complains about not being able to mutate immutable variable v
, the Nickname
struct definition is missing and, even with derive_more
crate in the project, the AsRef<str>
trait is not implemented on Nickname
. The AsRef
derive macro instead generates the AsRef<String>
implementation.
Possible fixes
derive_more
crate should be mentioned.
use derive_more::{AsMut, AsRef};
- The use statement above should be added to both examples.
- The
Nickname
struct definition should be added to the second example. add_hi
function should have amut
keyword added to thev
argument in the second example.just_print_stringy
should have theAsRef<str>
trait bound changed toAsRef<String>
in the second example.
Denys commented
Thank you! Fixed)