Define Associated Type of Trait Bound on an Associate Type

Hi there,

I am not sure if I am phrasing my title correctly. But i.e. I want to know if there is a syntax for achieving the following:

trait InfoProvider {
    type Item;

trait First {
     type Info: InfoProvider; 

trait Second {
   type GetInfo: First<<Info as InfoProvider>::Item = u32>

How about this?

trait Second
    <Self::GetInfo as First>::Info: InfoProvider<Item = u32>,
   type GetInfo: First;

Thanks for the quick and perfect answer!

@alice sorry to bother you again. I have another question regarding "reading" this as the compiler would.

My current understanding is:

The trait Second only exists where its associated type GetInfo adheres to the trait bound.

But although, the trait Second does not exist in another definition and I can not define another trait Second with a less restrictive associated type, I still need to add this trait bound to every impl of

impl<T: Second> .

So do I understand it correctly, that it is rather a shortcoming of syntax and rustc's capabilities to detect that?

An impl block must always list all requirements for the impl block to apply.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.