rust-lang / impl-trait-utils

Utilities for working with impl traits in Rust.
Apache License 2.0
89 stars 9 forks source link

Add support for traits with generic parameters #19

Closed mendess closed 8 months ago

mendess commented 8 months ago

Add support of traits that have generic parameters. Resolving #16.

(Also I tried to sign the Google CLA as described in the CONTRIBUTING.md file, but I kept getting a A server error occurred, please try your request again. error)

andrewtoth commented 8 months ago

Would it also be possible to change the generic parameter name T for the blanket implementation to something less likely to cause a naming conflict? T is commonly used as a name for a generic type, but when using this macro it will not compile unless the parameter in the trait is renamed. Similarly, for generic types used at the function level.

For example, even with this PR merged, the following does not compile:

#[trait_variant::make(Trait: Send)]
trait LocalTrait<T> {
    async fn trait_fn() -> T;
}

and

#[trait_variant::make(Trait: Send)]
trait LocalTrait {
    async fn trait_fn<T>() -> T;
}

Perhaps change it to TraitVariantBlanketType or something?

mendess commented 8 months ago

@andrewtoth that's a good idea, done.

andrewtoth commented 8 months ago

Thanks! I see PR #20 will have a conflict because of this now though :(.

mendess commented 8 months ago

Thanks! I see PR #20 will have a conflict because of this now though :(.

That's okay. I'll fix the conflicts! I've already done so I could test both PRs in a real codebase