3

I have a marker trait PoisonPill which is implemented by certain structs. I would like to implement it for a tuple (L, R) if EITHER L or R implements PoisonPill (not necessarily both). Is it possible to do that in Rust 2018, and how? Preferably stable Rust.

I tried the following:

trait PoisonPill {}

impl<L, R: PoisonPill> PoisonPill for (L, R) {}
impl<L: PoisonPill, R> PoisonPill for (L, R) {}

but get the E0119 compiler error because of overlapping definitions.

quant_dev
  • 6,181
  • 1
  • 34
  • 57
  • 1
    There is currently [no way](https://github.com/rust-lang/rust/issues/42721) to tell the compiler that `L` and `R` respectively do not implement `PoisonPill`, which would solve your problem. [Specialization](https://doc.rust-lang.org/unstable-book/language-features/specialization.html) may also help, but it is currently unstable. – EvilTak Apr 17 '21 at 17:06
  • Partial specialization is currently not correctly designed and implemented in Rust 2018, and even unreasonably not scheduled. – Alsein Apr 19 '21 at 06:28

0 Answers0