The compiler clearly warns me about the ambiguity: error[E0221]: ambiguous associated type Output in bounds of revlog::Revlog<'a>. I tried several way to do fully qualified names, but my homemade guess doesn't work.
First, you don’t have trait objects in the map there. You’d need to put a box around Revlog and RevEntry (if you intend to own the object).
Second, I’m not sure how you can disambiguate there. Typically you’d use a projection to get at an associated type of something generic (ie <T as SomeTrait>::Associated) but you need the starting T. Here there’s no real starting T, just the abstract Revlog trait. There’s no Self in scope either because we’re not “inside” the trait definition. Conceptually, it seems like it should be possible to say what you want here. Maybe there’s some syntax for it that someone knows. I suspect it’ll be a serious eyesore!
Third, you’d need to specify both Output associated types here (if this is possible), one for each Index impl. Would they both be a RevEntry trait object?
Can you elaborate on why you want Revlog to require those Index impls? If there are certain places where you need indexing, perhaps you can require the Index impls just there?
I suspect there’s a way to redesign some of this to make things easier.
Thank you, @vitalyd! I am working on implementing a program used to be in Python, so I mindset was not so right. For the first point, you are quite right, after putting on my static-lang hat, I figure that out. Thank you for bringing this up!
The original program can index the revlog by sequential number and SHA-1 hash, so I did use Index and Index. I re-design this part, as some other requirements, the ops overloading is not a good idea for me now.
I guess I dodged the second problem, I fail to solve this part.
Ok, it’s good that you’re able to sidestep this issue. What you were trying to do is possible with generics by making use of the where clause. A contrived example (Revlog definition same as before):
You can do a similar thing for generic struct definitions or impl blocks because they support the where clause. But I don’t know how you’d declare a trait object similar to this.