1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-03-20 22:36:03 +02:00

Merge pull request #22 from Arthur-Milchior/patch-1

Clarify from/into
This commit is contained in:
Martin Geisler 2022-12-22 13:23:55 +01:00 committed by GitHub
commit 15b8ca8a05
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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.