@@ -38,6 +38,11 @@ use crate::util::{self, internal, Config, Progress, ProgressStyle};
38
38
// TODO: is `manifest_path` a relic?
39
39
#[ derive( Clone ) ]
40
40
pub struct Package {
41
+ inner : Rc < PackageInner > ,
42
+ }
43
+
44
+ #[ derive( Clone ) ]
45
+ struct PackageInner {
41
46
/// The package's manifest.
42
47
manifest : Manifest ,
43
48
/// The root of the package.
@@ -88,9 +93,9 @@ impl ser::Serialize for Package {
88
93
where
89
94
S : ser:: Serializer ,
90
95
{
91
- let summary = self . manifest . summary ( ) ;
96
+ let summary = self . manifest ( ) . summary ( ) ;
92
97
let package_id = summary. package_id ( ) ;
93
- let manmeta = self . manifest . metadata ( ) ;
98
+ let manmeta = self . manifest ( ) . metadata ( ) ;
94
99
let license = manmeta. license . as_deref ( ) ;
95
100
let license_file = manmeta. license_file . as_deref ( ) ;
96
101
let description = manmeta. description . as_deref ( ) ;
@@ -103,7 +108,7 @@ impl ser::Serialize for Package {
103
108
// detail that is probably not relevant externally. There's also not a
104
109
// real path to show in `src_path`, and this avoids changing the format.
105
110
let targets: Vec < & Target > = self
106
- . manifest
111
+ . manifest ( )
107
112
. targets ( )
108
113
. iter ( )
109
114
. filter ( |t| t. src_path ( ) . is_path ( ) )
@@ -121,16 +126,16 @@ impl ser::Serialize for Package {
121
126
dependencies : summary. dependencies ( ) ,
122
127
targets,
123
128
features : summary. features ( ) ,
124
- manifest_path : & self . manifest_path ,
125
- metadata : self . manifest . custom_metadata ( ) ,
129
+ manifest_path : self . manifest_path ( ) ,
130
+ metadata : self . manifest ( ) . custom_metadata ( ) ,
126
131
authors,
127
132
categories,
128
133
keywords,
129
134
readme,
130
135
repository,
131
- edition : & self . manifest . edition ( ) . to_string ( ) ,
132
- links : self . manifest . links ( ) ,
133
- metabuild : self . manifest . metabuild ( ) ,
136
+ edition : & self . manifest ( ) . edition ( ) . to_string ( ) ,
137
+ links : self . manifest ( ) . links ( ) ,
138
+ metabuild : self . manifest ( ) . metabuild ( ) ,
134
139
publish : self . publish ( ) . as_ref ( ) ,
135
140
}
136
141
. serialize ( s)
@@ -141,58 +146,60 @@ impl Package {
141
146
/// Creates a package from a manifest and its location.
142
147
pub fn new ( manifest : Manifest , manifest_path : & Path ) -> Package {
143
148
Package {
144
- manifest,
145
- manifest_path : manifest_path. to_path_buf ( ) ,
149
+ inner : Rc :: new ( PackageInner {
150
+ manifest,
151
+ manifest_path : manifest_path. to_path_buf ( ) ,
152
+ } ) ,
146
153
}
147
154
}
148
155
149
156
/// Gets the manifest dependencies.
150
157
pub fn dependencies ( & self ) -> & [ Dependency ] {
151
- self . manifest . dependencies ( )
158
+ self . manifest ( ) . dependencies ( )
152
159
}
153
160
/// Gets the manifest.
154
161
pub fn manifest ( & self ) -> & Manifest {
155
- & self . manifest
162
+ & self . inner . manifest
156
163
}
157
164
/// Gets the manifest.
158
165
pub fn manifest_mut ( & mut self ) -> & mut Manifest {
159
- & mut self . manifest
166
+ & mut Rc :: make_mut ( & mut self . inner ) . manifest
160
167
}
161
168
/// Gets the path to the manifest.
162
169
pub fn manifest_path ( & self ) -> & Path {
163
- & self . manifest_path
170
+ & self . inner . manifest_path
164
171
}
165
172
/// Gets the name of the package.
166
173
pub fn name ( & self ) -> InternedString {
167
174
self . package_id ( ) . name ( )
168
175
}
169
176
/// Gets the `PackageId` object for the package (fully defines a package).
170
177
pub fn package_id ( & self ) -> PackageId {
171
- self . manifest . package_id ( )
178
+ self . manifest ( ) . package_id ( )
172
179
}
173
180
/// Gets the root folder of the package.
174
181
pub fn root ( & self ) -> & Path {
175
- self . manifest_path . parent ( ) . unwrap ( )
182
+ self . manifest_path ( ) . parent ( ) . unwrap ( )
176
183
}
177
184
/// Gets the summary for the package.
178
185
pub fn summary ( & self ) -> & Summary {
179
- self . manifest . summary ( )
186
+ self . manifest ( ) . summary ( )
180
187
}
181
188
/// Gets the targets specified in the manifest.
182
189
pub fn targets ( & self ) -> & [ Rc < Target > ] {
183
- self . manifest . targets ( )
190
+ self . manifest ( ) . targets ( )
184
191
}
185
192
/// Gets the current package version.
186
193
pub fn version ( & self ) -> & Version {
187
194
self . package_id ( ) . version ( )
188
195
}
189
196
/// Gets the package authors.
190
197
pub fn authors ( & self ) -> & Vec < String > {
191
- & self . manifest . metadata ( ) . authors
198
+ & self . manifest ( ) . metadata ( ) . authors
192
199
}
193
200
/// Returns `true` if the package is set to publish.
194
201
pub fn publish ( & self ) -> & Option < Vec < String > > {
195
- self . manifest . publish ( )
202
+ self . manifest ( ) . publish ( )
196
203
}
197
204
/// Returns `true` if this package is a proc-macro.
198
205
pub fn proc_macro ( & self ) -> bool {
@@ -206,8 +213,10 @@ impl Package {
206
213
207
214
pub fn map_source ( self , to_replace : SourceId , replace_with : SourceId ) -> Package {
208
215
Package {
209
- manifest : self . manifest . map_source ( to_replace, replace_with) ,
210
- manifest_path : self . manifest_path ,
216
+ inner : Rc :: new ( PackageInner {
217
+ manifest : self . manifest ( ) . clone ( ) . map_source ( to_replace, replace_with) ,
218
+ manifest_path : self . manifest_path ( ) . to_owned ( ) ,
219
+ } ) ,
211
220
}
212
221
}
213
222
@@ -276,7 +285,7 @@ impl hash::Hash for Package {
276
285
/// This is primarily used to convert a set of `PackageId`s to `Package`s. It
277
286
/// will download as needed, or used the cached download if available.
278
287
pub struct PackageSet < ' cfg > {
279
- packages : HashMap < PackageId , LazyCell < Rc < Package > > > ,
288
+ packages : HashMap < PackageId , LazyCell < Package > > ,
280
289
sources : RefCell < SourceMap < ' cfg > > ,
281
290
config : & ' cfg Config ,
282
291
multi : Multi ,
@@ -440,7 +449,7 @@ impl<'cfg> PackageSet<'cfg> {
440
449
} )
441
450
}
442
451
443
- pub fn get_one ( & self , id : PackageId ) -> CargoResult < & Rc < Package > > {
452
+ pub fn get_one ( & self , id : PackageId ) -> CargoResult < & Package > {
444
453
if let Some ( pkg) = self . packages . get ( & id) . and_then ( |slot| slot. borrow ( ) ) {
445
454
return Ok ( pkg) ;
446
455
}
@@ -450,7 +459,7 @@ impl<'cfg> PackageSet<'cfg> {
450
459
pub fn get_many (
451
460
& self ,
452
461
ids : impl IntoIterator < Item = PackageId > ,
453
- ) -> CargoResult < Vec < & Rc < Package > > > {
462
+ ) -> CargoResult < Vec < & Package > > {
454
463
let mut pkgs = Vec :: new ( ) ;
455
464
let mut downloads = self . enable_download ( ) ?;
456
465
for id in ids {
@@ -576,13 +585,13 @@ impl<'a, 'cfg> Downloads<'a, 'cfg> {
576
585
/// Returns `None` if the package is queued up for download and will
577
586
/// eventually be returned from `wait_for_download`. Returns `Some(pkg)` if
578
587
/// the package is ready and doesn't need to be downloaded.
579
- pub fn start ( & mut self , id : PackageId ) -> CargoResult < Option < & ' a Rc < Package > > > {
588
+ pub fn start ( & mut self , id : PackageId ) -> CargoResult < Option < & ' a Package > > {
580
589
Ok ( self
581
590
. start_inner ( id)
582
591
. chain_err ( || format ! ( "failed to download `{}`" , id) ) ?)
583
592
}
584
593
585
- fn start_inner ( & mut self , id : PackageId ) -> CargoResult < Option < & ' a Rc < Package > > > {
594
+ fn start_inner ( & mut self , id : PackageId ) -> CargoResult < Option < & ' a Package > > {
586
595
// First up see if we've already cached this package, in which case
587
596
// there's nothing to do.
588
597
let slot = self
@@ -607,7 +616,7 @@ impl<'a, 'cfg> Downloads<'a, 'cfg> {
607
616
let ( url, descriptor) = match pkg {
608
617
MaybePackage :: Ready ( pkg) => {
609
618
debug ! ( "{} doesn't need a download" , id) ;
610
- assert ! ( slot. fill( Rc :: new ( pkg) ) . is_ok( ) ) ;
619
+ assert ! ( slot. fill( pkg) . is_ok( ) ) ;
611
620
return Ok ( Some ( slot. borrow ( ) . unwrap ( ) ) ) ;
612
621
}
613
622
MaybePackage :: Download { url, descriptor } => ( url, descriptor) ,
@@ -720,7 +729,7 @@ impl<'a, 'cfg> Downloads<'a, 'cfg> {
720
729
/// # Panics
721
730
///
722
731
/// This function will panic if there are no remaining downloads.
723
- pub fn wait ( & mut self ) -> CargoResult < & ' a Rc < Package > > {
732
+ pub fn wait ( & mut self ) -> CargoResult < & ' a Package > {
724
733
let ( dl, data) = loop {
725
734
assert_eq ! ( self . pending. len( ) , self . pending_ids. len( ) ) ;
726
735
let ( token, result) = self . wait_for_curl ( ) ?;
@@ -833,7 +842,7 @@ impl<'a, 'cfg> Downloads<'a, 'cfg> {
833
842
. set ( self . next_speed_check . get ( ) + finish_dur) ;
834
843
835
844
let slot = & self . set . packages [ & dl. id ] ;
836
- assert ! ( slot. fill( Rc :: new ( pkg) ) . is_ok( ) ) ;
845
+ assert ! ( slot. fill( pkg) . is_ok( ) ) ;
837
846
Ok ( slot. borrow ( ) . unwrap ( ) )
838
847
}
839
848
0 commit comments