An iterator can be transformed to a collection using the Iterator trait's collect method if the collection implements FromIterator.
let vec = (0..10).collect::<Vec<_>>();
let devec = (0..10).collect::<VecDeque<_>>();
Vec and VecDeque implement FromIterator trait.
The implementation of Iterator::collect method is:
fn collect<B: FromIterator<Self::Item>>(self) -> B
where
Self: Sized,
{
FromIterator::from_iter(self)
}
How does Rust understand to call from_iter method of Vec or VecDeque from FromIterator::from_iter(self)?