#rust people:
Is it possible to implement a trait for a function via an attribute macro? Like this

fn not_implemented() {}

#[do_it]
fn implemented() {}

use_impl(not_implemented); // Err: trait `MyImpl` is not implemented
use_impl(implemented); // works

#rustlang

@lixou I think what you want is a [derive macro](https://doc.rust-lang.org/reference/procedural-macros.html#derive-macros), which is a form of procedural macro.

There is a [proc macro workshop](https://github.com/dtolnay/proc-macro-workshop#attribute-macro-sorted) that will teach you a lot about writing proc macros. The author of the repo had also implemented some of the workshop items, such as [seq](https://github.com/dtolnay/seq-macro), which you can use as reference.

Procedural Macros - The Rust Reference

@fd2 I’ve already worked with proc macros but I only know them for structs / enums. So my question was if smth like what I asked for is possible with functions. Like the `Fn` trait is also implemented for them so maybe there’s a way 
@lixou Ah yea, then I think maybe blanket implementation is a more apt solution here.
@fd2 blanket implementation?

@lixou : https://users.rust-lang.org/t/what-are-blanket-implementations/49904

There are a lot of examples of blanket implementation I think. Here is one example I found just looking around: https://docs.rs/quote/1.0.32/quote/trait.ToTokens.html#impl-ToTokens-for-%26'a+mut+T

So maybe your trait could be implemented via a blanket implementation like this: impl CustomTrait for T where T: Fn...

Although, I still think there is a way to do this via derive macro. An example would be #[tokio::main]. I am not familiar with derive macro to know off of the top of my head how that would be done.

What are blanket implementations

Guys, in documentation I see section called "blanket implementation". Could anyone please tell me what is it? Thanks

The Rust Programming Language Forum
@fd2 well blanket implementations would be error prone because with my example from the main thread both of the functions have the same signature. Derive macros could add source code but for that it must be possible to write a impl for a specific function only which I didn’t found existing thus asking here. But I think my only chance is to RFC to rust
@lixou Yea you're right. Do update us on it for when you figure it out though! I am very curious to see how it can be done as well.