Skip to content

romnn/box-dyn

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

box-dyn

build status test status crates.io docs.rs

A simple macro, here is how to use it:

#[box_dyn::box_dyn]
trait MyTrait {
    fn method_a(&self, param: usize) -> String;
    fn method_b(&mut self);
}

This will automatically implement MyTrait for Box<T: MyTrait>:

impl<T> MyTrait for Box<T> where T: MyTrait {
    fn method_a(&self, param: usize) -> String {
        MyTrait::method_a(self.as_ref(), param)
    }
    fn method_b(&mut self) {
        MyTrait::method_b(self.as_mut())
    }
}