is_trait

Macro is_trait 

Source
macro_rules! is_trait {
    ($type:ty, $trait:path) => { ... };
}
Expand description

See crate level docs for usage

Under the hood, this macro creates trait A and struct B<T>

B<T> implements std::ops::Deref to ()

A is implemented for () to return false

A is implemented for B<T> where T: SomeTrait to return true

We then call A on B::<SomeType>. Because of rust dereferencing rules, if SomeType is SomeTrait, then we call A on B<T> which is true. However, if SomeType is not SomeTrait, we dereference B<T> into () and call A on that, which is false