Returning Proxies from Index/IndexMut

I think that the most interesting is #3:

// Attempt 3 (RFC #192 a.k.a lifetime bounds)
trait Index2<I, R: 'a> {
    // R: 'a means that all the references contained in R must *outlive*
    // 'a, this is the *opposite* of what's required for the Vec case
    // For the Vec case, the lifetimes of the references in R must be equal
    // or *shorter* than 'a
    fn index2(&'a self, index: &I) -> R;
}

However indeed there is an issue with the specification of bounds on the type parameters; it seems that:

  • for arguments, you want a “longer than” relationship
  • for results, you want a “shorter than” relationship

but maybe an explicit syntax might be better. R: <'a and R: >'a ? Neither seems too satisfactory.

Is there no other place where we need to specify, generically, that the result’s lifetime should not exceed one of the parameters without assuming it is a reference ?

I tried to look at the Iterator interface but it circumvents the issue either by:

  • passing self by value, thus having the result taking ownership (does not seem quite what I would want here)
  • using a concrete type that is bound, circumventing the HKT issue