-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
From/Into section 6.1 introduction confusing #1149
Comments
I'm a random Rust n00b going through rust-by-example, and I also noticed this. After staring at it for a while, I actually think it would be an improvement if the first two sentences were simply deleted. I.e., just drop: "The From and Into traits are inherently linked, and this is actually part of its implementation. If you are able to convert type A from type B, then it should be easy to believe that we should be able to convert type B to type A." |
Hi, I thought this was confusing too and I came to open an issue. The example in the book only shows how to convert A to B (using both These two points should be emphasized:
There was a third claim on the above, closed, PR:
3 appears to be not true, according to this error I got today: error[E0117]: only traits defined in the current crate can be implemented for types defined outside of the crate
--> crypto/shared/src/constraints.rs:27:1
|
27 | impl Into<sp_core::H160> for H160 {
| ^^^^^-------------------^^^^^----
| | | |
| | | `primitive_types::H160` is not defined in the current crate
| | `sp_core::H160` is not defined in the current crate
| impl doesn't use only types from inside the current crate
|
= note: define and implement a trait or new type instead If someone elaborate on the idiomatic way to allow for type conversion between types in different crates, I will open a new PR with these changes. Using a new arbitrary trait seems dirty. Thanks! |
cc @marioidival for visibility |
The introductory text of section 6.1 suggests that the reciprocal Into trait for a From trait does the conversion in the opposite direction. (type A to B, type B to A).
This is confusing because the conversion is always type A to B, but the From/Into difference is which type it is initiated by.
The text was updated successfully, but these errors were encountered: