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.
Think of collect() as a bucket that gathers items from a stream. You use it when you have a list of items being processed one by one and need to store the final results in a list or map. It turns a sequence of actions into a concrete data structure you can use later.