mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-03-21 14:46:37 +02:00
commit
15b8ca8a05
@ -23,8 +23,9 @@ Implementing these traits is how a type expresses that it can be converted into
|
|||||||
another type.
|
another type.
|
||||||
|
|
||||||
The standard library has an implementation of `From<i8> for i16`, which means
|
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
|
that we can convert a variable `x` of type `i8` to an `i16` by calling
|
||||||
`i8`.
|
`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.
|
1. Execute the above program and look at the compiler error.
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user