I am reading the async book. In section async lifetimes there is a code snippet whose grammar I am not familiar with:
fn foo_expanded<'a>(x: &'a u8) -> impl Future<Output = u8> + 'a {
async move { *x }
}
In impl Future<Output = u8> + 'a, what is impl Trait + 'lifetime here?
Update: I am more asking what it is instead of the lifetime logic explanation. A definition from the official doc will be much appreciated.
It is an Impl trait, here particularly used as an abstract return type
Where the grammar of
TypeParamBoundsallows both trait and lifetime boundsParticularly noting that the grammar of
TypeParamBoundsis one or optionally severalTypeParamBounds combined, each of which in turn is eitherTraitBoundorLifetime(bounds).Specifying Multiple Trait Bounds with the + Syntax describe in some detail that we may combine more than one trait bound, but the same applies for lifetime bounds (where the grammar allows it). One could argue that the section should also mention lifetime bounds.