@@ -198,7 +198,8 @@ impl IndexSummary {
198
198
#[ derive( Deserialize , Serialize ) ]
199
199
pub struct IndexPackage < ' a > {
200
200
/// Name of the package.
201
- pub name : InternedString ,
201
+ #[ serde( borrow) ]
202
+ pub name : Cow < ' a , str > ,
202
203
/// The version of this dependency.
203
204
pub vers : Version ,
204
205
/// All kinds of direct dependencies of the package, including dev and
@@ -207,14 +208,14 @@ pub struct IndexPackage<'a> {
207
208
pub deps : Vec < RegistryDependency < ' a > > ,
208
209
/// Set of features defined for the package, i.e., `[features]` table.
209
210
#[ serde( default ) ]
210
- pub features : BTreeMap < InternedString , Vec < InternedString > > ,
211
+ pub features : BTreeMap < Cow < ' a , str > , Vec < Cow < ' a , str > > > ,
211
212
/// This field contains features with new, extended syntax. Specifically,
212
213
/// namespaced features (`dep:`) and weak dependencies (`pkg?/feat`).
213
214
///
214
215
/// This is separated from `features` because versions older than 1.19
215
216
/// will fail to load due to not being able to parse the new syntax, even
216
217
/// with a `Cargo.lock` file.
217
- pub features2 : Option < BTreeMap < InternedString , Vec < InternedString > > > ,
218
+ pub features2 : Option < BTreeMap < Cow < ' a , str > , Vec < Cow < ' a , str > > > > ,
218
219
/// Checksum for verifying the integrity of the corresponding downloaded package.
219
220
pub cksum : String ,
220
221
/// If `true`, Cargo will skip this version when resolving.
@@ -226,7 +227,7 @@ pub struct IndexPackage<'a> {
226
227
///
227
228
/// Added early 2018 (see <https://github.com/rust-lang/cargo/pull/4978>),
228
229
/// can be `None` if published before then.
229
- pub links : Option < InternedString > ,
230
+ pub links : Option < Cow < ' a , str > > ,
230
231
/// Required version of rust
231
232
///
232
233
/// Corresponds to `package.rust-version`.
@@ -263,7 +264,11 @@ impl IndexPackage<'_> {
263
264
fn to_summary ( & self , source_id : SourceId ) -> CargoResult < Summary > {
264
265
// ****CAUTION**** Please be extremely careful with returning errors, see
265
266
// `IndexSummary::parse` for details
266
- let pkgid = PackageId :: new ( self . name . into ( ) , self . vers . clone ( ) , source_id) ;
267
+ let pkgid = PackageId :: new (
268
+ InternedString :: new ( & self . name ) ,
269
+ self . vers . clone ( ) ,
270
+ source_id,
271
+ ) ;
267
272
let deps = self
268
273
. deps
269
274
. iter ( )
@@ -272,24 +277,31 @@ impl IndexPackage<'_> {
272
277
let mut features = self . features . clone ( ) ;
273
278
if let Some ( features2) = & self . features2 {
274
279
for ( name, values) in features2 {
275
- features. entry ( * name) . or_default ( ) . extend ( values) ;
280
+ features
281
+ . entry ( name. clone ( ) )
282
+ . or_default ( )
283
+ . extend ( values. iter ( ) . cloned ( ) ) ;
276
284
}
277
285
}
278
- let mut summary = Summary :: new (
279
- pkgid,
280
- deps,
281
- & features,
282
- self . links ,
283
- self . rust_version . clone ( ) ,
284
- ) ?;
286
+ let features = features
287
+ . into_iter ( )
288
+ . map ( |( name, values) | {
289
+ (
290
+ InternedString :: new ( & name) ,
291
+ values. iter ( ) . map ( |v| InternedString :: new ( & v) ) . collect ( ) ,
292
+ )
293
+ } )
294
+ . collect :: < BTreeMap < _ , _ > > ( ) ;
295
+ let links = self . links . as_ref ( ) . map ( |l| InternedString :: new ( & l) ) ;
296
+ let mut summary = Summary :: new ( pkgid, deps, & features, links, self . rust_version . clone ( ) ) ?;
285
297
summary. set_checksum ( self . cksum . clone ( ) ) ;
286
298
Ok ( summary)
287
299
}
288
300
}
289
301
290
302
#[ derive( Deserialize , Serialize ) ]
291
- struct IndexPackageMinimum {
292
- name : InternedString ,
303
+ struct IndexPackageMinimum < ' a > {
304
+ name : Cow < ' a , str > ,
293
305
vers : Version ,
294
306
}
295
307
@@ -308,13 +320,14 @@ struct IndexPackageV {
308
320
pub struct RegistryDependency < ' a > {
309
321
/// Name of the dependency. If the dependency is renamed, the original
310
322
/// would be stored in [`RegistryDependency::package`].
311
- pub name : InternedString ,
323
+ #[ serde( borrow) ]
324
+ pub name : Cow < ' a , str > ,
312
325
/// The SemVer requirement for this dependency.
313
326
#[ serde( borrow) ]
314
327
pub req : Cow < ' a , str > ,
315
328
/// Set of features enabled for this dependency.
316
329
#[ serde( default ) ]
317
- pub features : Vec < InternedString > ,
330
+ pub features : Vec < Cow < ' a , str > > ,
318
331
/// Whether or not this is an optional dependency.
319
332
#[ serde( default ) ]
320
333
pub optional : bool ,
@@ -329,7 +342,7 @@ pub struct RegistryDependency<'a> {
329
342
// `None` if it is from the same index.
330
343
pub registry : Option < Cow < ' a , str > > ,
331
344
/// The original name if the dependency is renamed.
332
- pub package : Option < InternedString > ,
345
+ pub package : Option < Cow < ' a , str > > ,
333
346
/// Whether or not this is a public dependency. Unstable. See [RFC 1977].
334
347
///
335
348
/// [RFC 1977]: https://rust-lang.github.io/rfcs/1977-public-private-dependencies.html
@@ -759,7 +772,7 @@ impl IndexSummary {
759
772
Ok ( ( index, summary) ) => ( index, summary, true ) ,
760
773
Err ( err) => {
761
774
let Ok ( IndexPackageMinimum { name, vers } ) =
762
- serde_json:: from_slice :: < IndexPackageMinimum > ( line)
775
+ serde_json:: from_slice :: < IndexPackageMinimum < ' _ > > ( line)
763
776
else {
764
777
// If we can't recover, prefer the original error
765
778
return Err ( err) ;
@@ -833,9 +846,13 @@ impl<'a> RegistryDependency<'a> {
833
846
default
834
847
} ;
835
848
836
- let mut dep = Dependency :: parse ( package. unwrap_or ( name) , Some ( & req) , id) ?;
849
+ let interned_name = package
850
+ . as_ref ( )
851
+ . map ( |p| InternedString :: new ( & p) )
852
+ . unwrap_or ( InternedString :: new ( & name) ) ;
853
+ let mut dep = Dependency :: parse ( interned_name, Some ( & req) , id) ?;
837
854
if package. is_some ( ) {
838
- dep. set_explicit_name_in_toml ( name) ;
855
+ dep. set_explicit_name_in_toml ( InternedString :: new ( & name) ) ;
839
856
}
840
857
let kind = match kind. as_deref ( ) . unwrap_or ( "" ) {
841
858
"dev" => DepKind :: Development ,
@@ -869,6 +886,10 @@ impl<'a> RegistryDependency<'a> {
869
886
dep. set_artifact ( artifact) ;
870
887
}
871
888
889
+ let features = features
890
+ . iter ( )
891
+ . map ( |f| InternedString :: new ( & f) )
892
+ . collect :: < Vec < _ > > ( ) ;
872
893
dep. set_optional ( optional)
873
894
. set_default_features ( default_features)
874
895
. set_features ( features)
0 commit comments