It would be very odd behavior IMO because the ref/deref dispatch we do only on the reciever, which has the keyword self. This is why self doesnât take a type and is a keyword in Rust and not a convention (like it is in Python).
The point you make about specialization is especially strong, sometimes we talk about specialization using free functions as examples, but free functions canât actually be specialized (well they can if you dispatch them to trait functions, but thatâs not a great solution).
From a high level, it certainly seems to me like this should work (whether or not you think its good style):
// import the items associated with Iterator into scope
use std::iter::Iterator::*;
fn foo(vec: Vec<i32>) -> Vec<i32> {
collect(map(vec, |x| x * 2))
}
I donât know why that doesnât work today, I suspect one of two things: a) its just a legacy bug that it doesnât work, b) there are gnarly edge cases that we donât know how to resolve, so its an active choice not to make it work.
@scott brought up the other day that it would be nice to have zip as a free function in the prelude, so cases like this would be nicer:
for (x, y) in zip(xs, ys) {
...
}