I can fix the error message by replacing typeof(plus_one) with fn(&i32) -> i32, but I assume this prevents inlining of the plus_one function and hence comes with a potentially hefty performance penalty.
All right. So I guess for the time being my two options are to either take the performance hit or write my own iterator adapter equivalent to .map(plus_one).
Interesting. I guess the point is that when the compiler sees MyStruct::iter(), it can infer a tighter return type than then one specified? But this would no longer work once I have Box<dyn RefToI32Collection>::iter(), right?
At least in simple case it will be - this playground, when using the "show assembly" option, shows that do_iter doesn't use neither plus_one nor MyStruct::iter, so the whole thing was indeed inlined.
It doesn't really have anything to do with the type. It depends on the semantics and complexity of the code, and how smart the optimizer is. Even Box<dyn Fn(…) -> …> can be de-virtualized in theory, although I don't know how much of that is being done.