Crates.io | autoimpl |
lib.rs | autoimpl |
version | 0.1.0 |
source | src |
created_at | 2017-04-12 20:39:47.856714 |
updated_at | 2017-04-12 20:39:47.856714 |
description | The user-facing part of the autoimpl macro. Automatically implement a generic trait using autoimpl! |
homepage | |
repository | https://github.com/blakepettersson/autoimpl |
max_upload_size | |
id | 10434 |
size | 1,619 |
Do you have a generic trait? Do you feel that adding a blanket impl for it is unnecessary repetition? Then this is the macro for you! This is a macro based on proc-macro-hack that helps to reduce some of the repetition, which works with any Rust version >= 1.15.0.
The autoimpl!
macro generates a default blanket impl for a generic trait for all T
with the same bounds as the
trait passed into the autoimpl!
block.
autoimpl!
blockautoimpl!
block per module. #[macro_use] extern crate autoimpl;
struct Dog {}
struct Duck {}
fn main() {
autoimpl! {
trait Quack<T> {
fn say(&self) -> String {
"quack".to_string()
}
}
}
let dog = Dog {};
let duck = Duck {};
assert_eq!(dog.say(), duck.say());
}