News for hackers. Stuff that matters.
Re:Fighting Rust's Expressive Type System by capitol_ on Sunday October 25, 2020 @04:11AM (#24884649)
One thing of roughly this nature is that a lot of rust code that I have read have their own types for iterators of objects.

For example, in the git2 crate there is both:

https://docs.rs/git2/0.13.12/git2/struct.Branch.html

and

https://docs.rs/git2/0.13.12/git2/struct.Branches.html

Where Branches implements Iterator.

Re:Fighting Rust's Expressive Type System by masklinn on Sunday October 25, 2020 @05:28AM (#24884969)
That seems pretty natural? The only reason why you don't have this in e.g. python is that iterators are often implemented as generators, so the "own type of iterator" is implicit. But I remember pretty much the same thing from my Java days, if you need to iterate you have to create an iterator type. It's a bit less visible due to type erasure but it's there nonetheless.
Re:Fighting Rust's Expressive Type System by ReactiveJelly on Sunday October 25, 2020 @10:56AM (#24886734)
Yeah it's not intuitive, but there isn't really another way to do it, right? Every concrete iterator is specific to what it returns and what it iterates over.

I think it's documented under something like "How to implement Iterator" but if that's not where people will go looking when they need it, then it should be somewhere else.

Re:Fighting Rust's Expressive Type System by lostmsu on Monday October 26, 2020 @02:56AM (#24893456)
In C# and Python you can write an iterator using `yield` keyword. E.g.

   for(i in array) yield i
The language then transforms this into an implementation of the base iterator interface under the hood.