@@ -15,7 +15,7 @@ use crate::{Index, Verbatim};
1515
1616static PYPI_URL : LazyLock < Url > = LazyLock :: new ( || Url :: parse ( "https://pypi.org/simple" ) . unwrap ( ) ) ;
1717
18- static DEFAULT_INDEX_URL : LazyLock < Index > = LazyLock :: new ( || {
18+ static DEFAULT_INDEX : LazyLock < Index > = LazyLock :: new ( || {
1919 Index :: from_index_url ( IndexUrl :: Pypi ( VerbatimUrl :: from_url ( PYPI_URL . clone ( ) ) ) )
2020} ) ;
2121
@@ -235,7 +235,7 @@ impl<'a> IndexLocations {
235235 . iter ( )
236236 . filter ( move |index| index. name . as_ref ( ) . map_or ( true , |name| seen. insert ( name) ) )
237237 . find ( |index| index. default && !index. explicit )
238- . or_else ( || Some ( & DEFAULT_INDEX_URL ) )
238+ . or_else ( || Some ( & DEFAULT_INDEX ) )
239239 }
240240 }
241241
@@ -299,16 +299,41 @@ impl<'a> IndexLocations {
299299 }
300300 }
301301
302- /// Return an iterator over all allowed [`Index`] entries.
302+ /// Return a vector containing all allowed [`Index`] entries.
303303 ///
304- /// This includes explicit indexes, implicit indexes flat indexes, and the default index.
304+ /// This includes explicit indexes, implicit indexes, flat indexes, and the default index.
305305 ///
306- /// If `no_index` was enabled, then this always returns an empty iterator.
307- pub fn allowed_indexes ( & ' a self ) -> impl Iterator < Item = & ' a Index > + ' a {
308- self . flat_indexes ( )
309- . chain ( self . explicit_indexes ( ) )
310- . chain ( self . implicit_indexes ( ) )
311- . chain ( self . default_index ( ) )
306+ /// The indexes will be returned in the order in which they were defined, such that the
307+ /// last-defined index is the last item in the vector.
308+ pub fn allowed_indexes ( & ' a self ) -> Vec < & ' a Index > {
309+ if self . no_index {
310+ self . flat_index . iter ( ) . rev ( ) . collect ( )
311+ } else {
312+ let mut indexes = vec ! [ ] ;
313+
314+ let mut seen = FxHashSet :: default ( ) ;
315+ let mut default = false ;
316+ for index in {
317+ self . indexes
318+ . iter ( )
319+ . chain ( self . flat_index . iter ( ) )
320+ . filter ( move |index| index. name . as_ref ( ) . map_or ( true , |name| seen. insert ( name) ) )
321+ } {
322+ if index. default && !index. explicit {
323+ if default {
324+ continue ;
325+ }
326+ default = true ;
327+ }
328+ indexes. push ( index) ;
329+ }
330+ if !default {
331+ indexes. push ( & * DEFAULT_INDEX ) ;
332+ }
333+
334+ indexes. reverse ( ) ;
335+ indexes
336+ }
312337 }
313338}
314339
@@ -337,7 +362,7 @@ impl<'a> IndexUrls {
337362 . iter ( )
338363 . filter ( move |index| index. name . as_ref ( ) . map_or ( true , |name| seen. insert ( name) ) )
339364 . find ( |index| index. default && !index. explicit )
340- . or_else ( || Some ( & DEFAULT_INDEX_URL ) )
365+ . or_else ( || Some ( & DEFAULT_INDEX ) )
341366 }
342367 }
343368
0 commit comments