Comment

Comment by estebank

Because Rust has restrictions on what can be impl'd to containing at least one local type/trait.

    impl Foo<X> for Y {}
         ^^^---     ^ one of these two has to belong to your current crate
            |
            this part doesn't matter
If you tried

    impl ForeignTrait for ForeignType {}
You get a compile error, hence why you can sometimes hear people suggesting using a new-type

    struct LocalType(ForeignType);
    impl ForeignTrait for LocalType {}
                          ^^^^^^^^^ this is a local type, so it compiles
This restriction is to avoid allowing semver footguns, where changes in a dependency of a dependency can cause your current crate to stop compiling after a seemingly innocuous upstream change.

With that context

    impl Into<Result<U, E>> for &T
         ^^^^                    ^ could be foreign?
         |
         foreign (from std::)
If you want to provide your users with a way to call .into() on a type you provide, that can be converted to a type they wrote, you need to be able to express the opposite construct, hence `From`

    impl From<Foreign> for Local
         ^^^^ -------      ^^^^^ local type, so the impl is allowed
         |    |
         |    foreign, but it doesn't matter
         foreign (from std::)
parent estebank 4 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton