@@ -38,6 +38,11 @@ use crate::util::{self, internal, Config, Progress, ProgressStyle};
3838// TODO: is `manifest_path` a relic?
3939#[ derive( Clone ) ]
4040pub struct Package {
41+ inner : Rc < PackageInner > ,
42+ }
43+
44+ #[ derive( Clone ) ]
45+ struct PackageInner {
4146 /// The package's manifest.
4247 manifest : Manifest ,
4348 /// The root of the package.
@@ -88,9 +93,9 @@ impl ser::Serialize for Package {
8893 where
8994 S : ser:: Serializer ,
9095 {
91- let summary = self . manifest . summary ( ) ;
96+ let summary = self . manifest ( ) . summary ( ) ;
9297 let package_id = summary. package_id ( ) ;
93- let manmeta = self . manifest . metadata ( ) ;
98+ let manmeta = self . manifest ( ) . metadata ( ) ;
9499 let license = manmeta. license . as_deref ( ) ;
95100 let license_file = manmeta. license_file . as_deref ( ) ;
96101 let description = manmeta. description . as_deref ( ) ;
@@ -103,7 +108,7 @@ impl ser::Serialize for Package {
103108 // detail that is probably not relevant externally. There's also not a
104109 // real path to show in `src_path`, and this avoids changing the format.
105110 let targets: Vec < & Target > = self
106- . manifest
111+ . manifest ( )
107112 . targets ( )
108113 . iter ( )
109114 . filter ( |t| t. src_path ( ) . is_path ( ) )
@@ -121,16 +126,16 @@ impl ser::Serialize for Package {
121126 dependencies : summary. dependencies ( ) ,
122127 targets,
123128 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 ( ) ,
126131 authors,
127132 categories,
128133 keywords,
129134 readme,
130135 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 ( ) ,
134139 publish : self . publish ( ) . as_ref ( ) ,
135140 }
136141 . serialize ( s)
@@ -141,58 +146,60 @@ impl Package {
141146 /// Creates a package from a manifest and its location.
142147 pub fn new ( manifest : Manifest , manifest_path : & Path ) -> Package {
143148 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+ } ) ,
146153 }
147154 }
148155
149156 /// Gets the manifest dependencies.
150157 pub fn dependencies ( & self ) -> & [ Dependency ] {
151- self . manifest . dependencies ( )
158+ self . manifest ( ) . dependencies ( )
152159 }
153160 /// Gets the manifest.
154161 pub fn manifest ( & self ) -> & Manifest {
155- & self . manifest
162+ & self . inner . manifest
156163 }
157164 /// Gets the manifest.
158165 pub fn manifest_mut ( & mut self ) -> & mut Manifest {
159- & mut self . manifest
166+ & mut Rc :: make_mut ( & mut self . inner ) . manifest
160167 }
161168 /// Gets the path to the manifest.
162169 pub fn manifest_path ( & self ) -> & Path {
163- & self . manifest_path
170+ & self . inner . manifest_path
164171 }
165172 /// Gets the name of the package.
166173 pub fn name ( & self ) -> InternedString {
167174 self . package_id ( ) . name ( )
168175 }
169176 /// Gets the `PackageId` object for the package (fully defines a package).
170177 pub fn package_id ( & self ) -> PackageId {
171- self . manifest . package_id ( )
178+ self . manifest ( ) . package_id ( )
172179 }
173180 /// Gets the root folder of the package.
174181 pub fn root ( & self ) -> & Path {
175- self . manifest_path . parent ( ) . unwrap ( )
182+ self . manifest_path ( ) . parent ( ) . unwrap ( )
176183 }
177184 /// Gets the summary for the package.
178185 pub fn summary ( & self ) -> & Summary {
179- self . manifest . summary ( )
186+ self . manifest ( ) . summary ( )
180187 }
181188 /// Gets the targets specified in the manifest.
182189 pub fn targets ( & self ) -> & [ Rc < Target > ] {
183- self . manifest . targets ( )
190+ self . manifest ( ) . targets ( )
184191 }
185192 /// Gets the current package version.
186193 pub fn version ( & self ) -> & Version {
187194 self . package_id ( ) . version ( )
188195 }
189196 /// Gets the package authors.
190197 pub fn authors ( & self ) -> & Vec < String > {
191- & self . manifest . metadata ( ) . authors
198+ & self . manifest ( ) . metadata ( ) . authors
192199 }
193200 /// Returns `true` if the package is set to publish.
194201 pub fn publish ( & self ) -> & Option < Vec < String > > {
195- self . manifest . publish ( )
202+ self . manifest ( ) . publish ( )
196203 }
197204 /// Returns `true` if this package is a proc-macro.
198205 pub fn proc_macro ( & self ) -> bool {
@@ -206,8 +213,10 @@ impl Package {
206213
207214 pub fn map_source ( self , to_replace : SourceId , replace_with : SourceId ) -> Package {
208215 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+ } ) ,
211220 }
212221 }
213222
@@ -276,7 +285,7 @@ impl hash::Hash for Package {
276285/// This is primarily used to convert a set of `PackageId`s to `Package`s. It
277286/// will download as needed, or used the cached download if available.
278287pub struct PackageSet < ' cfg > {
279- packages : HashMap < PackageId , LazyCell < Rc < Package > > > ,
288+ packages : HashMap < PackageId , LazyCell < Package > > ,
280289 sources : RefCell < SourceMap < ' cfg > > ,
281290 config : & ' cfg Config ,
282291 multi : Multi ,
@@ -440,7 +449,7 @@ impl<'cfg> PackageSet<'cfg> {
440449 } )
441450 }
442451
443- pub fn get_one ( & self , id : PackageId ) -> CargoResult < & Rc < Package > > {
452+ pub fn get_one ( & self , id : PackageId ) -> CargoResult < & Package > {
444453 if let Some ( pkg) = self . packages . get ( & id) . and_then ( |slot| slot. borrow ( ) ) {
445454 return Ok ( pkg) ;
446455 }
@@ -450,7 +459,7 @@ impl<'cfg> PackageSet<'cfg> {
450459 pub fn get_many (
451460 & self ,
452461 ids : impl IntoIterator < Item = PackageId > ,
453- ) -> CargoResult < Vec < & Rc < Package > > > {
462+ ) -> CargoResult < Vec < & Package > > {
454463 let mut pkgs = Vec :: new ( ) ;
455464 let mut downloads = self . enable_download ( ) ?;
456465 for id in ids {
@@ -576,13 +585,13 @@ impl<'a, 'cfg> Downloads<'a, 'cfg> {
576585 /// Returns `None` if the package is queued up for download and will
577586 /// eventually be returned from `wait_for_download`. Returns `Some(pkg)` if
578587 /// 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 > > {
580589 Ok ( self
581590 . start_inner ( id)
582591 . chain_err ( || format ! ( "failed to download `{}`" , id) ) ?)
583592 }
584593
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 > > {
586595 // First up see if we've already cached this package, in which case
587596 // there's nothing to do.
588597 let slot = self
@@ -607,7 +616,7 @@ impl<'a, 'cfg> Downloads<'a, 'cfg> {
607616 let ( url, descriptor) = match pkg {
608617 MaybePackage :: Ready ( pkg) => {
609618 debug ! ( "{} doesn't need a download" , id) ;
610- assert ! ( slot. fill( Rc :: new ( pkg) ) . is_ok( ) ) ;
619+ assert ! ( slot. fill( pkg) . is_ok( ) ) ;
611620 return Ok ( Some ( slot. borrow ( ) . unwrap ( ) ) ) ;
612621 }
613622 MaybePackage :: Download { url, descriptor } => ( url, descriptor) ,
@@ -720,7 +729,7 @@ impl<'a, 'cfg> Downloads<'a, 'cfg> {
720729 /// # Panics
721730 ///
722731 /// 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 > {
724733 let ( dl, data) = loop {
725734 assert_eq ! ( self . pending. len( ) , self . pending_ids. len( ) ) ;
726735 let ( token, result) = self . wait_for_curl ( ) ?;
@@ -833,7 +842,7 @@ impl<'a, 'cfg> Downloads<'a, 'cfg> {
833842 . set ( self . next_speed_check . get ( ) + finish_dur) ;
834843
835844 let slot = & self . set . packages [ & dl. id ] ;
836- assert ! ( slot. fill( Rc :: new ( pkg) ) . is_ok( ) ) ;
845+ assert ! ( slot. fill( pkg) . is_ok( ) ) ;
837846 Ok ( slot. borrow ( ) . unwrap ( ) )
838847 }
839848
0 commit comments