box-dyn

Crates.iobox-dyn
lib.rsbox-dyn
version0.0.8
sourcesrc
created_at2024-05-24 18:12:35.234166
updated_at2024-05-24 20:44:45.889392
descriptionMacro to derive the implementation of Trait for Box
homepagehttps://github.com/romnn/box-dyn
repositoryhttps://github.com/romnn/box-dyn
max_upload_size
id1251401
size13,966
Roman Dahm (romnn)

documentation

https://docs.rs/box-dyn

README

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())
    }
}
Commit count: 17

cargo fmt