mirror of
https://github.com/google/comprehensive-rust.git
synced 2024-11-28 18:11:07 +02:00
Clarify from/into
I found the phrasing confusing. Mentionning that a class implements From and then using `into()` seems confusing. It looks like that you meant that it implements `Into`. So I believe that a little more details may help show why this exercise is valid. I would have considered clarifying that `into` does not need to specify that we use the implementation for `i16` thanks to type analysis, but I assume this would add too much text, and this can either be ignored by the reader for the time being, or guessed
This commit is contained in:
parent
b411aa688a
commit
638dde7704
@ -23,8 +23,9 @@ Implementing these traits is how a type expresses that it can be converted into
|
||||
another type.
|
||||
|
||||
The standard library has an implementation of `From<i8> for i16`, which means
|
||||
that we can convert an `i8` to an `i16` by calling the `into()` method on the
|
||||
`i8`.
|
||||
that we can convert a variable `x` of type `i8` to an `i16` by calling
|
||||
`i16::from(x)`. Or, simpler, with `x.into()`, because `From<i8> for i16`
|
||||
implementation automatically create an implementation of `Into<i16> for i8`.
|
||||
|
||||
1. Execute the above program and look at the compiler error.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user