1+ use std:: cell:: OnceCell ;
12use std:: cell:: { Cell , Ref , RefCell , RefMut } ;
23use std:: cmp:: Ordering ;
34use std:: collections:: { BTreeMap , BTreeSet , HashMap , HashSet } ;
@@ -12,7 +13,6 @@ use anyhow::Context as _;
1213use cargo_util_schemas:: manifest:: { Hints , RustVersion } ;
1314use curl:: easy:: Easy ;
1415use curl:: multi:: { EasyHandle , Multi } ;
15- use lazycell:: LazyCell ;
1616use semver:: Version ;
1717use serde:: Serialize ;
1818use tracing:: debug;
@@ -287,7 +287,7 @@ impl hash::Hash for Package {
287287/// This is primarily used to convert a set of `PackageId`s to `Package`s. It
288288/// will download as needed, or used the cached download if available.
289289pub struct PackageSet < ' gctx > {
290- packages : HashMap < PackageId , LazyCell < Package > > ,
290+ packages : HashMap < PackageId , OnceCell < Package > > ,
291291 sources : RefCell < SourceMap < ' gctx > > ,
292292 gctx : & ' gctx GlobalContext ,
293293 multi : Multi ,
@@ -408,7 +408,7 @@ impl<'gctx> PackageSet<'gctx> {
408408 Ok ( PackageSet {
409409 packages : package_ids
410410 . iter ( )
411- . map ( |& id| ( id, LazyCell :: new ( ) ) )
411+ . map ( |& id| ( id, OnceCell :: new ( ) ) )
412412 . collect ( ) ,
413413 sources : RefCell :: new ( sources) ,
414414 gctx,
@@ -423,7 +423,7 @@ impl<'gctx> PackageSet<'gctx> {
423423 }
424424
425425 pub fn packages ( & self ) -> impl Iterator < Item = & Package > {
426- self . packages . values ( ) . filter_map ( |p| p. borrow ( ) )
426+ self . packages . values ( ) . filter_map ( |p| p. get ( ) )
427427 }
428428
429429 pub fn enable_download < ' a > ( & ' a self ) -> CargoResult < Downloads < ' a , ' gctx > > {
@@ -457,7 +457,7 @@ impl<'gctx> PackageSet<'gctx> {
457457 }
458458
459459 pub fn get_one ( & self , id : PackageId ) -> CargoResult < & Package > {
460- if let Some ( pkg) = self . packages . get ( & id) . and_then ( |slot| slot. borrow ( ) ) {
460+ if let Some ( pkg) = self . packages . get ( & id) . and_then ( |slot| slot. get ( ) ) {
461461 return Ok ( pkg) ;
462462 }
463463 Ok ( self . get_many ( Some ( id) ) ?. remove ( 0 ) )
@@ -700,7 +700,7 @@ impl<'a, 'gctx> Downloads<'a, 'gctx> {
700700 . packages
701701 . get ( & id)
702702 . ok_or_else ( || internal ( format ! ( "couldn't find `{}` in package set" , id) ) ) ?;
703- if let Some ( pkg) = slot. borrow ( ) {
703+ if let Some ( pkg) = slot. get ( ) {
704704 return Ok ( Some ( pkg) ) ;
705705 }
706706
@@ -717,8 +717,8 @@ impl<'a, 'gctx> Downloads<'a, 'gctx> {
717717 let ( url, descriptor, authorization) = match pkg {
718718 MaybePackage :: Ready ( pkg) => {
719719 debug ! ( "{} doesn't need a download" , id) ;
720- assert ! ( slot. fill ( pkg) . is_ok( ) ) ;
721- return Ok ( Some ( slot. borrow ( ) . unwrap ( ) ) ) ;
720+ assert ! ( slot. set ( pkg) . is_ok( ) ) ;
721+ return Ok ( Some ( slot. get ( ) . unwrap ( ) ) ) ;
722722 }
723723 MaybePackage :: Download {
724724 url,
@@ -941,8 +941,8 @@ impl<'a, 'gctx> Downloads<'a, 'gctx> {
941941 . set ( self . next_speed_check . get ( ) + finish_dur) ;
942942
943943 let slot = & self . set . packages [ & dl. id ] ;
944- assert ! ( slot. fill ( pkg) . is_ok( ) ) ;
945- Ok ( slot. borrow ( ) . unwrap ( ) )
944+ assert ! ( slot. set ( pkg) . is_ok( ) ) ;
945+ Ok ( slot. get ( ) . unwrap ( ) )
946946 }
947947
948948 fn enqueue ( & mut self , dl : Download < ' gctx > , handle : Easy ) -> CargoResult < ( ) > {
0 commit comments