How to use collect

Use the collect() method on an iterator to convert it into a collection like a Vec or HashMap.

Use the collect() method on an iterator to consume it and produce a collection like a Vec or HashMap.

let numbers: Vec<i32> = (1..=5).collect();

The collect() method takes the iterator and converts it into the collection type specified by the variable annotation or type inference.