| Crates.io | autotrait |
| lib.rs | autotrait |
| version | 0.2.1 |
| created_at | 2025-04-22 20:27:32.329879+00 |
| updated_at | 2025-05-08 22:02:16.450935+00 |
| description | Reduces boilerplate by auto-generating trait definitions from impl blocks for dynamic dispatch. |
| homepage | |
| repository | https://github.com/bearcove/autotrait |
| max_upload_size | |
| id | 1644582 |
| size | 20,543 |
Sometimes you want to do dynamic dispatch. First you'd have to define a trait:
trait Trait {
fn do_stuff(&self) -> String;
}
And then implement it on something:
struct Impl;
impl Trait for Impl {
fn do_stuff(&self) -> String {
// do stuff here
todo!()
}
}
We're repeating ourselves a bunch when doing that! What if we could just do:
struct Impl;
#[autotrait::autotrait]
impl Trait for Impl {
fn do_stuff(&self) -> String {
// do stuff here
todo!()
}
}
That way we wouldn't even have to define the trait!
Well, that's what this crates does.