logo
macro_rules! assert_impl_one {
    ($x:ty: $($t:path),+ $(,)?) => { ... };
}
Expand description

Asserts that the type implements exactly one in a set of traits.

Related:

Examples

Given some type Foo, it is expected to implement either Snap, Crackle, or Pop:

struct Foo;

trait Snap {}
trait Crackle {}
trait Pop {}

assert_impl_one!(Foo: Snap, Crackle, Pop);

If only Crackle is implemented, the assertion passes:

impl Crackle for Foo {}

assert_impl_one!(Foo: Snap, Crackle, Pop);

If Snap or Pop is also implemented, the assertion fails:

impl Pop for Foo {}

assert_impl_one!(Foo: Snap, Crackle, Pop);