@@ -212,6 +212,16 @@ impl IndexSummary {
212212 }
213213 }
214214
215+ /// Extract the summary from any variant
216+ pub fn into_summary ( self ) -> Summary {
217+ match self {
218+ IndexSummary :: Candidate ( sum)
219+ | IndexSummary :: Yanked ( sum)
220+ | IndexSummary :: Offline ( sum)
221+ | IndexSummary :: Unsupported ( sum, _) => sum,
222+ }
223+ }
224+
215225 /// Extract the package id from any variant
216226 pub fn package_id ( & self ) -> PackageId {
217227 match self {
@@ -221,6 +231,22 @@ impl IndexSummary {
221231 | IndexSummary :: Unsupported ( sum, _) => sum. package_id ( ) ,
222232 }
223233 }
234+
235+ /// Returns `true` if the index summary is [`Yanked`].
236+ ///
237+ /// [`Yanked`]: IndexSummary::Yanked
238+ #[ must_use]
239+ pub fn is_yanked ( & self ) -> bool {
240+ matches ! ( self , Self :: Yanked ( ..) )
241+ }
242+
243+ /// Returns `true` if the index summary is [`Offline`].
244+ ///
245+ /// [`Offline`]: IndexSummary::Offline
246+ #[ must_use]
247+ pub fn is_offline ( & self ) -> bool {
248+ matches ! ( self , Self :: Offline ( ..) )
249+ }
224250}
225251
226252/// A representation of the cache on disk that Cargo maintains of summaries.
@@ -564,9 +590,9 @@ impl<'cfg> RegistryIndex<'cfg> {
564590 // offline will be displayed.
565591 let mut called = false ;
566592 let callback = & mut |s : IndexSummary | {
567- if !matches ! ( & s , & IndexSummary :: Offline ( _ ) ) {
593+ if !s . is_offline ( ) {
568594 called = true ;
569- f ( s. as_summary ( ) . clone ( ) ) ;
595+ f ( s. into_summary ( ) ) ;
570596 }
571597 } ;
572598 ready ! ( self . query_inner_with_online(
@@ -587,7 +613,7 @@ impl<'cfg> RegistryIndex<'cfg> {
587613 load,
588614 yanked_whitelist,
589615 & mut |s| {
590- f ( s. as_summary ( ) . clone ( ) ) ;
616+ f ( s. into_summary ( ) ) ;
591617 } ,
592618 true ,
593619 )
@@ -631,9 +657,7 @@ impl<'cfg> RegistryIndex<'cfg> {
631657 // Next filter out all yanked packages. Some yanked packages may
632658 // leak through if they're in a whitelist (aka if they were
633659 // previously in `Cargo.lock`
634- . filter ( |s| {
635- !matches ! ( s, IndexSummary :: Yanked ( _) ) || yanked_whitelist. contains ( & s. package_id ( ) )
636- } ) ;
660+ . filter ( |s| !s. is_yanked ( ) || yanked_whitelist. contains ( & s. package_id ( ) ) ) ;
637661
638662 // Handle `cargo update --precise` here.
639663 let precise = source_id. precise_registry_version ( name. as_str ( ) ) ;
@@ -677,7 +701,7 @@ impl<'cfg> RegistryIndex<'cfg> {
677701 let req = OptVersionReq :: exact ( pkg. version ( ) ) ;
678702 let found = ready ! ( self . summaries( pkg. name( ) , & req, load) ) ?
679703 . filter ( |s| s. package_id ( ) . version ( ) == pkg. version ( ) )
680- . any ( |summary| matches ! ( summary , IndexSummary :: Yanked ( _ ) ) ) ;
704+ . any ( |s| s . is_yanked ( ) ) ;
681705 Poll :: Ready ( Ok ( found) )
682706 }
683707}
@@ -990,12 +1014,12 @@ impl IndexSummary {
9901014 } ;
9911015
9921016 if v_max < v {
993- return Ok ( IndexSummary :: Unsupported ( summary, v) ) ;
994- }
995- if yanked. unwrap_or ( false ) {
996- return Ok ( IndexSummary :: Yanked ( summary) ) ;
1017+ Ok ( IndexSummary :: Unsupported ( summary, v) )
1018+ } else if yanked. unwrap_or ( false ) {
1019+ Ok ( IndexSummary :: Yanked ( summary) )
1020+ } else {
1021+ Ok ( IndexSummary :: Candidate ( summary) )
9971022 }
998- Ok ( IndexSummary :: Candidate ( summary) )
9991023 }
10001024}
10011025
0 commit comments