What is the 'rusty' equivalent to a IReadOnlyList (from .NET) as a function parameter?
I'm a C# programmer slowly learning rust, so I often find myself trying to find rust equivalents to stuff I am used to from .NET. Maybe this is not always the best idea, so if I should approach this problem in a completely different way, please do let me know.
Basically I want to write a function that takes some collection type that can be enumerated and indexed. Basically something like this:
fn my_function(collection: &mut Vec<Data>) {
// do something that requires mutating, indexing, enumerating and knowing the length of the collection
}
However, I would like to avoid explicitly specifying the type of my collection as Vec<Data>, as I might change the actual type later, e.g. to ArrayVec<Data> and I would like my function to work with that as well. In .NET I would use an IReadOnlyList (if I edit items in-place) or IList (if I need to add/remove items or change the order) interface here, but I couldn't really find an easy way to do the same in rust. I tried something like this with traits:
fn my_function<'a>(collection: &(impl IndexMut<&'a mut Data> + Iterator<Item = &'a mut Data>)) {
// do something that requires indexing, enumerating and knowing the length of the collection
}
But, apart from this looking quite intimidating with the lifetimes, I couldn't get it to compile.
How would I approach this in a 'rusty' way?