@@ -259,8 +259,36 @@ pub struct IndexPackage<'a> {
259
259
pub v : Option < u32 > ,
260
260
}
261
261
262
+ impl IndexPackage < ' _ > {
263
+ fn to_summary ( & self , source_id : SourceId ) -> CargoResult < Summary > {
264
+ // ****CAUTION**** Please be extremely careful with returning errors, see
265
+ // `IndexSummary::parse` for details
266
+ let pkgid = PackageId :: new ( self . name . into ( ) , self . vers . clone ( ) , source_id) ;
267
+ let deps = self
268
+ . deps
269
+ . iter ( )
270
+ . map ( |dep| dep. clone ( ) . into_dep ( source_id) )
271
+ . collect :: < CargoResult < Vec < _ > > > ( ) ?;
272
+ let mut features = self . features . clone ( ) ;
273
+ if let Some ( features2) = & self . features2 {
274
+ for ( name, values) in features2 {
275
+ features. entry ( * name) . or_default ( ) . extend ( values) ;
276
+ }
277
+ }
278
+ let mut summary = Summary :: new (
279
+ pkgid,
280
+ deps,
281
+ & features,
282
+ self . links ,
283
+ self . rust_version . clone ( ) ,
284
+ ) ?;
285
+ summary. set_checksum ( self . cksum . clone ( ) ) ;
286
+ Ok ( summary)
287
+ }
288
+ }
289
+
262
290
/// A dependency as encoded in the [`IndexPackage`] index JSON.
263
- #[ derive( Deserialize , Serialize ) ]
291
+ #[ derive( Deserialize , Serialize , Clone ) ]
264
292
pub struct RegistryDependency < ' a > {
265
293
/// Name of the dependency. If the dependency is renamed, the original
266
294
/// would be stored in [`RegistryDependency::package`].
@@ -706,32 +734,10 @@ impl IndexSummary {
706
734
// between different versions that understand the index differently.
707
735
// Make sure to consider the INDEX_V_MAX and CURRENT_CACHE_VERSION
708
736
// values carefully when making changes here.
709
- let IndexPackage {
710
- name,
711
- vers,
712
- cksum,
713
- deps,
714
- mut features,
715
- features2,
716
- yanked,
717
- links,
718
- rust_version,
719
- v,
720
- } = serde_json:: from_slice ( line) ?;
721
- let v = v. unwrap_or ( 1 ) ;
722
- tracing:: trace!( "json parsed registry {}/{}" , name, vers) ;
723
- let pkgid = PackageId :: new ( name. into ( ) , vers. clone ( ) , source_id) ;
724
- let deps = deps
725
- . into_iter ( )
726
- . map ( |dep| dep. into_dep ( source_id) )
727
- . collect :: < CargoResult < Vec < _ > > > ( ) ?;
728
- if let Some ( features2) = features2 {
729
- for ( name, values) in features2 {
730
- features. entry ( name) . or_default ( ) . extend ( values) ;
731
- }
732
- }
733
- let mut summary = Summary :: new ( pkgid, deps, & features, links, rust_version) ?;
734
- summary. set_checksum ( cksum) ;
737
+ let index: IndexPackage < ' _ > = serde_json:: from_slice ( line) ?;
738
+ let v = index. v . unwrap_or ( 1 ) ;
739
+ tracing:: trace!( "json parsed registry {}/{}" , index. name, index. vers) ;
740
+ let summary = index. to_summary ( source_id) ?;
735
741
736
742
let v_max = if bindeps {
737
743
INDEX_V_MAX + 1
@@ -741,7 +747,7 @@ impl IndexSummary {
741
747
742
748
if v_max < v {
743
749
Ok ( IndexSummary :: Unsupported ( summary, v) )
744
- } else if yanked. unwrap_or ( false ) {
750
+ } else if index . yanked . unwrap_or ( false ) {
745
751
Ok ( IndexSummary :: Yanked ( summary) )
746
752
} else {
747
753
Ok ( IndexSummary :: Candidate ( summary) )
0 commit comments