georust / gdal

Rust bindings for GDAL
https://crates.io/crates/gdal
MIT License
359 stars 94 forks source link

[Feature] Add `DriverIterator` to iterate through the available drivers #512

Closed Atreyagaurav closed 9 months ago

Atreyagaurav commented 9 months ago

Following up from the discussions in #510.

I was thinking about it and came across a potential problem. We can add and remove the drivers during runtime, so if we keep track of the index and increase that to get the Iterator::next(), then we'll run into:

So, to make sure this doesn't happen, we can take a Vec of the Drivers and make an iterator out of it, but that defeats the purpose of the Iterators. But maybe that'll work, as we don't have to call the get_driver(i) ourselves in a loop.

lnicola commented 9 months ago

I think we can call GDALGetDriver until it returns NULL, without checking the count. If the user adds new drivers during iterator, they might even get them back.

There's no safety issue and we can add a note saying it's a bad idea to register or unregister drivers during the iteration.