rust-lang-ua / rustcamp

Getting ready for prod

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Code examples in step 2.4 do not compile

PalaBeaveR opened this issue · comments

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 a mut keyword added to the v argument in the second example.
  • just_print_stringy should have the AsRef<str> trait bound changed to AsRef<String> in the second example.

Thank you! Fixed)