Conflicting implementation

trait TraitA {
    fn name(&self) -> String;
}
trait TraitB {
    fn hello(&self) -> String;
}
struct St<T>(T);
impl<T: TraitB> TraitB for St<T> {
    fn hello(&self) -> String {
        self.0.hello()
    }
}
impl<T: TraitA> TraitB for St<T> {
    fn hello(&self) -> String {
        format!("hello, {}", self.0.name())
    }
}

error[E0119]: conflicting implementations of trait pyo3::FromPyObject<'_> for type ffi::py::serde::FromFfi<_>

I want to impl TraitB for St<T>, if T had impl TraitA and not impl TraitB.

Rust doesn't support such negative reasoning. It would make it a breaking change for T to implement TraitB.

It may gain limited support, where T has to be explicitly opted-out of implementing TraitB:

impl !TraitB for SomeT;

But even that is a ways out, I imagine.

1 Like