On Wed, Jun 26, 2013 at 6:49 PM, Gareth Smith
<[email protected]> wrote:
> One downside of external iterators is that they produce function signatures
> that expose implementation details and are harder to understand.
>
> For example, an internal iterator function that loops over odd numbers would
> have a signature like this:
>
> fn each_odd(ints: &[int], fn(int) -> bool) -> bool;
>
> The same function written to produce an external iterator would have a
> signature more like this:
>
> fn iter_odds<'a>(ints: &'a [int]) -> iterator::FilterMapIterator<'a, &int,
> int, vec::VecIterator<'a, int>>;
>
> This signature is more complicated. It is also likely to change if the
> implementation of iter_odds changes (e.g. to no longer use filter_map).

You can implement a struct and make the fields private, no need to
expose the implementation details. A syntax for generators with
`yield` would do this for you.
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to