Tracking issue: returning iterators from trait methods #22
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
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 thenext_*_handle
andlast_*_handle
methods of theMesh
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.
The text was updated successfully, but these errors were encountered: