Re:Fighting Rust's Expressive Type System
by dochtman on Sunday October 25, 2020 @02:22AM
(#24884213)
Can you give an example of this? I'm very curious. As an experienced Rustacean, I kind of realize that there is a lot to idiomatic style, but at the same time I've assimilated it enough that it's often no longer obvious to me.
[ Parent
| on HN ]
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.