hobofan / ambassador

Delegation of trait implementations via procedural macros
Apache License 2.0
251 stars 13 forks source link

Error when trying to delegate a trait with multiple generics #38

Closed CJKay closed 2 years ago

CJKay commented 2 years ago

Hi folks, I'm having some trouble getting a trait with multiple generic type arguments to delegate. I couldn't find this in either the test or any of the examples, so I'm just wondering whether this is an undocumented limitation.

This works fine:

#[delegatable_trait]
pub trait Target<T> {}

pub struct SubTarget;

impl<T> Target<T> for SubTarget {}

#[derive(Delegate)]
#[delegate(Target<T>, generics = "T")]
pub struct SuperTarget(SubTarget);

This, on the other hand:

#[delegatable_trait]
pub trait Target<T, U> {}

pub struct SubTarget;

impl<T, U> Target<T, U> for SubTarget {}

#[derive(Delegate)]
#[delegate(Target<T, U>, generics = "T, U")]
pub struct SuperTarget(SubTarget);

Throws this error:

error: proc-macro derive panicked
  --> ...
   |
 1 | #[derive(Delegate)]
   |          ^^^^^^^^
   |
   = help: message: expected `,`
xis19 commented 2 years ago

I am seeing a similar issue when I tried to delegate std::ops::Index<usize, Output=T>