Is it possible to write impl on both general case and special case?

⚓ Rust    📅 2025-12-07    👤 surdeus    👁️ 3      

surdeus

I am making a type wrapper MyType for internal type T, and MyType can deref to T. When doing some related impl for traits.There are three cases.

  1. impl PartialEq for MyType
  2. impl PartialEq<ExternalType> for MyType
  3. impl PartialEq<MyType> for ExternalType

I have done the first case. And due to foreign trait for non-local type rule, I had to do the third case one by one.

But for second case, apparently impl<A: PartialEq<MyType>> PartialEq<A> for MyType {} conflicts with the first case. Is there a way to make this possible, somehow rule out MyType in A?

2 posts - 2 participants

Read full topic

🏷️ Rust_feed