Can someone help me to understand why I can't compile the following example?
struct Foo(Box<dyn Iterator<Item = u8>>);
impl FromIterator<u8> for Foo {
fn from_iter<T: IntoIterator<Item = u8>>(iter: T) -> Self {
Foo(Box::new(iter.into_iter()))
}
}
The compiler shows the following error:
error[E0310]: the associated type `<T as IntoIterator>::IntoIter` may not live long enough
--> src/lib.rs:5:13
|
5 | Foo(Box::new(iter.into_iter()))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider adding an explicit lifetime bound `<T as IntoIterator>::IntoIter: 'static`...
= note: ...so that the type `<T as IntoIterator>::IntoIter` will meet its required lifetime bounds
For more information about this error, try `rustc --explain E0310`.
For what I understand, when I call IntoIterator::into_iter()
I will have ownership of the iterator, so why do I still need to specify the 'static lifetime? (of course in this case - as far as I know - I can't even do that, since the bounds are defined on the FromIterator
trait).