Where this would be implemented for a type like the following
trait Thing<'a, S: ?Sized> {
fn new(t: &'a S) -> Self;
// more methods here ...
}
trait Support<'a> {
type Impl: Thing<'a, Self>;
}
// Implementation for [T]
struct ActualThing<'a, S: ?Sized> { s: &'a S }
impl<'a, S: ?Sized> Thing<'a, S> for ActualThing<'a, S> {
fn new(s: &'a S) -> Self {
Self { s }
}
}
impl<'a, T: 'a> Support<'a> for [T] {
type Impl = ActualThing<'a, Self>;
}
The problem
When implementing this for a type that is generic over another type (like the above), it requires a T: 'a bound. Which wouldn't normally be necessary if there wasn't a separate underlying implementation (the associated type).
When you have &'a [T] then it's always true that T: 'a, otherwise you'd have a dangling pointer. In a few places Rust will add T: 'a implicitly for you. But it's just not safe to ever have T that doesn't really outlive it being borrowed.
But in general you can't abstract away memory management in Rust.
In languages with a garbage collector there's no difference between owned and borrowed values, and object lifetimes are automatically extended to be correct for every use.
In Rust, the memory management has to be done by the code that uses the values, so every single use of a value needs to know whether it's dealing with a borrowed or owned value, and have enough information to ensure that it's not borrowed for too long. The compiler has to generate physically different code depending on whether you use Vec<u8> or &[u8].
If you want to make either borrowed or owned type usable behind an abstraction boundary, then the compiler will have to assume the worst, most restrictive subset of both. It can't let you keep the abstract object as if it was owned value in case it was actually borrowed. It can't let you freely copy around shared references, just in case the abstract object was actually a unique owner.
In some cases like Cow it's possible to replace lifetimes with 'static to support only the owned case. But usually you have to decide whether your trait is for owning, or borrowing objects, or shared and owning at the same time (Arc), and make that explicit.