I would like indexing of my type to return a structure bounded with lifetime. The structure needs to contain a reference to the original type to be able to run some methods on it, like foo[index].bar()
.
When I try a simple approach
impl<'a> Index<usize> for Foo {
type Output = FooIndex<'a>;
fn index(&self, index: usize) -> &Self::Output {
FooIndex {
index,
foo: &self,
}
}
}
I get the following
error[E0207]: the lifetime parameter 'a is not constrained by the impl trait, self type, or predicates
Is there any way how to do it?