trait_derive is a small crate that will generate a trait based on the impl blocks of your structs. This will save repitition in cases where you want to generate a trait for testing purposes, or you want to turn exsisting code into a trait for decoupling purposes.
To add it to your project, add the following line to your Cargo.toml
trait_derive = "0.1.0"
Currently, traitderive requires you to be running _nightly Rust. This will hopefully change in the future, once proc macros are stable.
Using this crate looks something like this: ``` rust
extern crate trait_derive;
use traitderive::maketrait;
pub struct A;
impl A { pub fn hello_world(&self) { println!("Hello, world!"); } }
fn takestrait(x: &TraitA) { x.helloworld(); }
fn basicusage() { let a = A { }; takestrait(&a); }
impl A { pub fn query(&self) -> u32 { 32 } } ```