Using generic iterators instead of specific list types

后端 未结 3 907
生来不讨喜
生来不讨喜 2020-12-05 14:53

I\'m very new to Rust, coming from C# / Java / similar.

In C# we have IEnumerable that can be used to iterate almost any kind of array or list.

3条回答
  •  孤街浪徒
    2020-12-05 15:30

    Implement the Iterator trait for the struct that should serve as iterator. You only need to implement the next method. The other methods have default implementations.

    It is not possible to create an iterator that works with any container. The type system machinery needed for this doesn't exist yet.

提交回复
热议问题