Macro trait_group::trait_group
[−]
[src]
macro_rules! trait_group { (@as_items $($it:item)*) => { ... }; (@replace_self with $rep:tt [$($st:tt)*] Self $($tail:tt)*) => { ... }; (@replace_self with $rep:tt [$($st:tt)*] $t:tt $($tail:tt)*) => { ... }; (@replace_self with $rep:tt [$($st:tt)*]) => { ... }; ($(#[$attr:meta])* pub trait $name:ident : $($t:tt)+) => { ... }; ($(#[$attr:meta])* trait $name:ident : $($t:tt)+) => { ... }; }
Create a new trait that acts like an alias or “group” of a bunch of traits.
The macro works by creating a new trait and making one blanket implementation
of it for all types that implement the traits in the group. It
replaces Self
automatically in the impl.
The trait may be declared with pub
or without.
Examples
#[macro_use] extern crate trait_group; use std::ops::Add; trait_group! { /// You can document the trait here pub trait CanAdd : Add<Self, Output=Self> + Copy } fn foo<T: CanAdd>(x: T) -> T { x + x } fn main() { println!("{}", foo(2)); }