Macro substrate::type_dispatch::dispatch_impl
source · dispatch_impl!() { /* proc-macro */ }
Expand description
A function-like variant of impl_dispatch
.
§Syntax
The syntax is the same as impl_dispatch
, but the contents of the attribute must now
be contained by brackets ([]
) or braces ({}
).
§Examples
struct GenericStruct<A, B>(A, B);
// Creates 4 trait implementations.
dispatch_impl!{
[{u64; u16}, {u32, usize; u8, u64}]
impl<A, B, C> Into<C> for GenericStruct<A, B> {
fn into(self) -> C {
self.0 as C + self.1 as C
}
}
}
let x: usize = GenericStruct(1u64, 3u32).into();
assert_eq!(x, 4);
let x: u64 = GenericStruct(1u64, 3u8).into();
assert_eq!(x, 4);
let x: usize = GenericStruct(1u16, 3u32).into();
assert_eq!(x, 4);
let x: u64 = GenericStruct(1u16, 3u8).into();
assert_eq!(x, 4);