Avatar ·

How to write a function in Rust that takes an iterator?

Hi everyone! I'm new to Rust and trying to write a function that can process a sequence of numbers from different sources: from a vector, from a range, from a file, etc. In other languages, I would just pass an array or list, but in Rust, as I understand, it's common to use iterators. The problem is that I don't understand how to properly declare the parameter type. I tried writing something like: ```rust fn sum_squares(items: Iterator) -> i32 { items.map(|x| x * x).sum() } fn main() { let vec = vec![1, 2, 3, 4, 5]; println!("{}", sum_squares(vec.iter())); } ``` But the compiler complains: "error[E0277]: the size for values of type `dyn Iterator` cannot be known at compilation time". I understand that this has something to do with traits and sizes in st