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
TypeParamBounds
allows both trait and lifetime boundsParticularly noting that the grammar of
TypeParamBounds
is one or optionally severalTypeParamBound
s combined, each of which in turn is eitherTraitBound
orLifetime
(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.