Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Why is a filtered iterator a different type than an unfiltered iterator?


This is hard to answer as a one-liner; do you know about monomorphic vs. polymorphic code and static/dynamic dispatching? Rust is, by default statically dispatched, so because the two kinds of iterators do different things, they have to be of different types.


Ah, that makes sense, thank you.

One iterator simply returns the value and increments, and the other needs to apply the filter first and potentially advance several times.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: