How to make mutex traits?

I have two traits: A and B, I want them all to implement a trait C automatically, but a type implements A may also implements B, I want them to be mutex.
I wrote this to do it: Rust Playground.
I don't know whether this way is sound or it has overhead.

Rust doesn't support mutually exclusive traits so far.

See for example

The latter proposal would let your code compile, but as noted in that PR, it would also allow mutually exclusive traits more generally, and thus it was postponed until a more comprehensive approach is decided on.

There has been some related experimentation recently (not stabilized):

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.