Skip to content

Automatically declare a trait given an impl block.

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

bearcove/autotrait

Repository files navigation

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
    }
}

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
    }
}

That way we wouldn't even have to define the trait!

Well, that's what this crates does.

About

Automatically declare a trait given an impl block.

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published