0

I have a code like this:

#[my_attribute]
impl<T> Foo<T> for Bar where T: Baz { ... }

How to get the Foo<T> part from ItemImpl?

Vlad
  • 3,001
  • 1
  • 22
  • 52

1 Answers1

1

The trait_ field of ItemImpl contains the information you are interested in

trait_: Option<(Option<Bang>, Path, For)>

It's an Option as impl blocks don't have to implement a trait (e.g. impl Baz { }). From the inner three-tuple, you are intersted in the second item, the Path. That contains your Foo<T>.

Lukas Kalbertodt
  • 79,749
  • 26
  • 255
  • 305
  • Thanks, already found it. If anyone is interested, the code looks like this: `&trait_def.trait_.as_ref().unwrap().1` – Vlad Nov 22 '20 at 21:54