autotrait

Crates.ioautotrait
lib.rsautotrait
version0.2.1
created_at2025-04-22 20:27:32.329879+00
updated_at2025-05-08 22:02:16.450935+00
descriptionReduces boilerplate by auto-generating trait definitions from impl blocks for dynamic dispatch.
homepage
repositoryhttps://github.com/bearcove/autotrait
max_upload_size
id1644582
size20,543
Amos Wenger (fasterthanlime)

documentation

https://docs.rs/autotrait

README

autotrait

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.

Commit count: 45

cargo fmt