Skip to content

Can't implement From or Into for custom wrapper type #49817

@clarfonthey

Description

@clarfonthey

This won't work:

pub struct Wrapper<T>(T);
impl<T> From<Wrapper<T>> for T {
    fn from(val: Wrapper<T>) -> T { val.0 }
}

and neither will:

pub struct Wrapper<T>(T);
impl<T> Into<T> for Wrapper<T> {
    fn into(self) -> T { self.0 }
}

In previous (post-1.0) versions of the compiler, the latter was able to be implemented, however, now it's seen as conflicting with impl<T, U> Into<U> for T where U: From<T>, which is definitely the correct behaviour.

But right now, not being able to implement From for this case seems very much to me like a bug.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.T-langRelevant to the language team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions