georust / rstar

R*-tree spatial index for the Rust ecosystem
https://docs.rs/rstar
Apache License 2.0
386 stars 67 forks source link

Implement `IntoIterator` for `RTree` #113

Closed jakoschiko closed 8 months ago

jakoschiko commented 1 year ago

Currently

Would it be possible to also implement IntoIterator<Item = T> for RTree<T> (that will be consumed)?

I would be happy to help with a PR.

urschrei commented 1 year ago

Does https://docs.rs/rstar/0.10.0/rstar/struct.RTree.html#method.drain help for your use case?

jakoschiko commented 1 year ago

Yes, I'm currently using this. But it would still be nice to have an implementation of IntoIterator<Item = T> because this would improve the interoperability with other collection types.

Example:

let rtree: RTree<Rectangle> = todo!();
let vec: Vec<Rectangle> = rtree.into_iterator().collect();

Edit: Uh, my fault. This also works with RTree::drain. I think I got confused after I got lifetime issues because the RTree is not owned by the iterator. So this issue is probably only relevant for those rare cases in which it's necessary that the iterator owns the RTree.