File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed
Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change 11# Changes
22
33## Unreleased
4+ - Add ` DriverIterator ` format to iterate through drivers, as well as ` DriverManager::all() ` method that provides the iterator.
5+
46- ** Breaking** : ` Feature::set_field_xxx ` now take ` &mut self `
57 - < https://github.com/georust/gdal/pull/505 >
68
Original file line number Diff line number Diff line change @@ -451,10 +451,39 @@ impl DriverManager {
451451 gdal_sys:: GDALDestroyDriverManager ( ) ;
452452 }
453453 }
454+
455+ /// Get an `Iterator` over for all the loaded drivers.
456+ ///
457+ /// Warning: Adding or removing drivers while consuming the
458+ /// iterator is safe, but can produce less useful results.
459+ pub fn all ( ) -> DriverIterator {
460+ DriverIterator { current : 0 }
461+ }
462+ }
463+
464+ /// Iterator for the registered [`Driver`]s in [`DriverManager`]
465+ pub struct DriverIterator {
466+ current : usize ,
467+ }
468+
469+ impl Iterator for DriverIterator {
470+ type Item = Driver ;
471+
472+ fn next ( & mut self ) -> Option < Self :: Item > {
473+ match DriverManager :: get_driver ( self . current ) {
474+ Ok ( d) => {
475+ self . current += 1 ;
476+ Some ( d)
477+ }
478+ Err ( _) => None ,
479+ }
480+ }
454481}
455482
456483#[ cfg( test) ]
457484mod tests {
485+ use std:: collections:: HashSet ;
486+
458487 use super :: * ;
459488
460489 #[ test]
@@ -466,4 +495,14 @@ mod tests {
466495 assert ! ( DriverManager :: count( ) > 0 ) ;
467496 assert ! ( DriverManager :: get_driver( 0 ) . is_ok( ) ) ;
468497 }
498+
499+ #[ test]
500+ fn test_driver_iterator ( ) {
501+ assert_eq ! ( DriverManager :: count( ) , DriverManager :: all( ) . count( ) ) ;
502+
503+ let drivers: HashSet < String > = DriverManager :: all ( ) . map ( |d| d. short_name ( ) ) . collect ( ) ;
504+ for i in 0 ..DriverManager :: count ( ) {
505+ assert ! ( drivers. contains( & DriverManager :: get_driver( i) . unwrap( ) . short_name( ) ) )
506+ }
507+ }
469508}
You can’t perform that action at this time.
0 commit comments