References in generic functions

Here's an earlier thread with an explanation.

TL;DR:

Yes it can, but that will result in a concrete reference type with a concrete lifetime. In contrast, the signature of filter() demands that the function be higher-ranked over the lifetime. This works when it is a closure or when it explicitly accepts a reference (because the compiler treats reference-typed function arguments specially), but a generic type parameter can't be instantiated to a higher-ranked reference; for<'a> &'a T is simply not a type (or a thing).

2 Likes