100-exercises-to-learn-rust
100-exercises-to-learn-rust copied to clipboard
Use the `From` trait instead of custom conversion method in exercise 06_01 solution
In the previous parts of the tutorial, the reader is taught about idiomatic ways to do fallible and infallible conversions between types using the From and TryFrom traits. Later, the exercise 06_01_arrays requires to convert an enum reference &Weekday into an usize, which gives an opportunity for the reader to see a practical use of the From trait.
Currently, the solutions branch implements a custom weekday2index method to do the conversion. It misses an opportunity to remind the readers about a notion learned in the previous chapters.
Update the solution of exercise 06_01_arrays to use an implementation of the From trait to convert &Weekday references to usize instead of using a weekday2index function.