Skip to content

Generic From impl for newtypes #20

@dhardy

Description

@dhardy

Creating a new issue because this is, in my opinion, probably the most commonly encountered and annoying to work around issue caused by no-orphan rules:

struct NewType<T>(T);

impl<A, B: From<A>> From<NewType<A>> for NewType<B> {
    fn from(a: NewType<A>) -> NewType<B> {
        NewType(a.0.into())
    }
}

Namely, the special case where A == B overlaps with the generic impl<T> From<T> for T.

It's also an instance where it's usually trivial to prove that the overlapping implementations are equivalent, though I realise this is probably not a productive path toward a solution.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions