#traits #macro #dx

combine_traits

A Macro to create Traits wich are just a combination of existing ones

3 releases

0.1.2 Jan 2, 2023
0.1.1 Jan 2, 2023
0.1.0 Jan 2, 2023

#2447 in Development tools

MIT license

4KB

combine_traits macro for rust

A combine_traits! is a single macro wich can be used to declare a new trait wich is no more than a combination of existing traits.

How to use

To create a new Trait call the macro combine_traits! with the name as the first argument. After a ; list all "sub_traits" seperated by ,.

Example:

use combine_traits::combine_traits;
use std::fmt::{Display, Debug};
combine_traits!(DisplayAndDebug; Display, Debug);
 
fn display_vs_debug<T: DisplayAndDebug>(x: T)->String {
    format!("Display:{}Debug:{:?}", x, x) }
assert_eq!(display_vs_debug(10), "Display:10Debug:10");

No runtime deps