single-trait-impl

Crates.iosingle-trait-impl
lib.rssingle-trait-impl
version0.1.0
sourcesrc
created_at2023-03-13 14:25:41.810786
updated_at2023-03-13 14:25:41.810786
descriptionA macro for declaring and implementing a trait at the same time.
homepage
repositoryhttps://github.com/M1cha/single-trait-impl
max_upload_size
id808887
size3,236
Michael Zimmermann (M1cha)

documentation

README

single-trait-impl

Provides a macro for declaring and implementing a trait at the same time. This can be useful when you simply want to add functionality to an existing struct but have no intention to implement it on other structs as well.

In other words, this macro reduces the verbosity of implementing your own trait for a single struct:

#[single_trait_impl]
impl SocketAddrEx for std::net::SocketAddr {
    fn useful_function(&self) {
    }
}

This will expand to the following code:

pub trait SocketAddrEx {
    fn useful_function(&self);
}

impl SocketAddrEx for std::net::SocketAddr {
    fn useful_function(&self) {
    }
}
Commit count: 1

cargo fmt