@@ -212,6 +212,16 @@ impl IndexSummary {
212
212
}
213
213
}
214
214
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
+
215
225
/// Extract the package id from any variant
216
226
pub fn package_id ( & self ) -> PackageId {
217
227
match self {
@@ -221,6 +231,22 @@ impl IndexSummary {
221
231
| IndexSummary :: Unsupported ( sum, _) => sum. package_id ( ) ,
222
232
}
223
233
}
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
+ }
224
250
}
225
251
226
252
/// A representation of the cache on disk that Cargo maintains of summaries.
@@ -564,9 +590,9 @@ impl<'cfg> RegistryIndex<'cfg> {
564
590
// offline will be displayed.
565
591
let mut called = false ;
566
592
let callback = & mut |s : IndexSummary | {
567
- if !matches ! ( & s , & IndexSummary :: Offline ( _ ) ) {
593
+ if !s . is_offline ( ) {
568
594
called = true ;
569
- f ( s. as_summary ( ) . clone ( ) ) ;
595
+ f ( s. into_summary ( ) ) ;
570
596
}
571
597
} ;
572
598
ready ! ( self . query_inner_with_online(
@@ -587,7 +613,7 @@ impl<'cfg> RegistryIndex<'cfg> {
587
613
load,
588
614
yanked_whitelist,
589
615
& mut |s| {
590
- f ( s. as_summary ( ) . clone ( ) ) ;
616
+ f ( s. into_summary ( ) ) ;
591
617
} ,
592
618
true ,
593
619
)
@@ -631,9 +657,7 @@ impl<'cfg> RegistryIndex<'cfg> {
631
657
// Next filter out all yanked packages. Some yanked packages may
632
658
// leak through if they're in a whitelist (aka if they were
633
659
// 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 ( ) ) ) ;
637
661
638
662
// Handle `cargo update --precise` here.
639
663
let precise = source_id. precise_registry_version ( name. as_str ( ) ) ;
@@ -677,7 +701,7 @@ impl<'cfg> RegistryIndex<'cfg> {
677
701
let req = OptVersionReq :: exact ( pkg. version ( ) ) ;
678
702
let found = ready ! ( self . summaries( pkg. name( ) , & req, load) ) ?
679
703
. filter ( |s| s. package_id ( ) . version ( ) == pkg. version ( ) )
680
- . any ( |summary| matches ! ( summary , IndexSummary :: Yanked ( _ ) ) ) ;
704
+ . any ( |s| s . is_yanked ( ) ) ;
681
705
Poll :: Ready ( Ok ( found) )
682
706
}
683
707
}
@@ -990,12 +1014,12 @@ impl IndexSummary {
990
1014
} ;
991
1015
992
1016
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) )
997
1022
}
998
- Ok ( IndexSummary :: Candidate ( summary) )
999
1023
}
1000
1024
}
1001
1025
0 commit comments