Hi, pretty new to Rust and thought I was getting a hang of the type system until I tried this:
trait MyTrait {
type FirstType;
type SecondType;
type IteratorType: Iterator<Item=(&Self::FirstType, &Self::SecondType)>
}
This doesn't compile because of something to do with lifetimes. My understanding of lifetime annotations is that they are a way to create death pacts between references. So I figured I want the two references returned by the iterator to be valid for the same time and tried my second approach:
trait MyTrait<'a> {
type FirstType;
type SecondType;
type IteratorType: Iterator<Item = (&'a Self::FirstType, &'a Self::SecondType)>
}
The compiler went nuts after this saying something about:
The associated type may not live long enough, consider adding an explicity lifetime bound
I ended up just copying the snippets the error gave me and ended up with this error instead
trait MyTrait<'a> {
type FirstType;
type SecondType;
type IteratorType: Iterator<Item = (&'a <Self as MyTrait<'a>>::FirstType: 'a, &'a <Self as MyTrait<'a>>::SecondType: 'a)>
}
associated const equality is incomplete
What is going on here?