Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tracking issue: returning iterators from trait methods #22

Closed
LukasKalbertodt opened this issue Aug 25, 2019 · 1 comment
Closed

Tracking issue: returning iterators from trait methods #22

LukasKalbertodt opened this issue Aug 25, 2019 · 1 comment
Labels
area:datastructures Area: mesh datastructures area:maps Area: property maps category:improvement Category: Improvement category:performance Category: performance/speed needs:rust-feature Needs: a new feature of Rust which is not yet implemented (in sufficient quality) status:blocked Status: this is blocked by something else

Comments

@LukasKalbertodt
Copy link
Owner

Returning iterators from trait methods is difficult as (a) usually every implementing type has a different iterator type and (b) this iterator type borrows from the collection. This is currently not (easily) expressible in Rust. The situation will be vastly improved by GATs. impl Trait for trait methods would make it even easier.

Until those features are implemented, we have to work around the problem. This is done in a number of different ways:

  • Mesh::{faces, vertices, edges}: here, there exists only one iterator type which uses the next_*_handle and last_*_handle methods of the Mesh trait. This means we have extracted the iterator logic into two "normal" functions in the trait. This only works because the iterator state is the same for all implementing types: a handle as the current "position" is sufficient. So this workaround doesn't work for situations where different implementors need different iterator state or the iterator logic is more complex.

  • Adjacency queries of meshes: here, a funky type system trick was used to work around the lack of GATs. It produces a bunch of verbose filler code, but it works. Each implementor has its own type.

  • PropStore: here, dynamic dispatch is used for now. Currently there is no urgent need to improve the speed of this iteration. This workaround could probably be replaced by the one of the adjacency queries, but it's not worth it yet.

@LukasKalbertodt LukasKalbertodt added category:improvement Category: Improvement needs:rust-feature Needs: a new feature of Rust which is not yet implemented (in sufficient quality) status:blocked Status: this is blocked by something else area:maps Area: property maps area:datastructures Area: mesh datastructures category:performance Category: performance/speed labels Aug 25, 2019
@LukasKalbertodt
Copy link
Owner Author

The latter two have been resolved by using GATs. The first mentioned one is a bit trickier. I opened #32 for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:datastructures Area: mesh datastructures area:maps Area: property maps category:improvement Category: Improvement category:performance Category: performance/speed needs:rust-feature Needs: a new feature of Rust which is not yet implemented (in sufficient quality) status:blocked Status: this is blocked by something else
Projects
None yet
Development

No branches or pull requests

1 participant