Here, you have used the inappropriate lifetime in the impl Trait,
The impl Trait can only capture lifetimes bound at the fn or impl
level.
To fix this we have to define the lifetime at the function or impl
level and use that lifetime in the impl Trait. For example you can
define the lifetime at the function: