cargo::core::package

Struct Downloads

source
pub struct Downloads<'a, 'gctx> {
Show 17 fields set: &'a PackageSet<'gctx>, pending: HashMap<usize, (Download<'gctx>, EasyHandle)>, pending_ids: HashSet<PackageId>, sleeping: SleepTracker<(Download<'gctx>, Easy)>, results: Vec<(usize, Result<(), Error>)>, next: usize, progress: RefCell<Option<Progress<'gctx>>>, downloads_finished: usize, downloaded_bytes: u64, largest: (u64, InternedString), start: Instant, success: bool, timeout: HttpTimeout, updated_at: Cell<Instant>, next_speed_check: Cell<Instant>, next_speed_check_bytes_threshold: Cell<u64>, _lock: CacheLock<'gctx>,
}
Expand description

Helper for downloading crates.

Fields§

§set: &'a PackageSet<'gctx>§pending: HashMap<usize, (Download<'gctx>, EasyHandle)>

When a download is started, it is added to this map. The key is a “token” (see Download::token). It is removed once the download is finished.

§pending_ids: HashSet<PackageId>

Set of packages currently being downloaded. This should stay in sync with pending.

§sleeping: SleepTracker<(Download<'gctx>, Easy)>

Downloads that have failed and are waiting to retry again later.

§results: Vec<(usize, Result<(), Error>)>

The final result of each download. A pair (token, result). This is a temporary holding area, needed because curl can report multiple downloads at once, but the main loop (wait) is written to only handle one at a time.

§next: usize

The next ID to use for creating a token (see Download::token).

§progress: RefCell<Option<Progress<'gctx>>>

Progress bar.

§downloads_finished: usize

Number of downloads that have successfully finished.

§downloaded_bytes: u64

Total bytes for all successfully downloaded packages.

§largest: (u64, InternedString)

Size (in bytes) and package name of the largest downloaded package.

§start: Instant

Time when downloading started.

§success: bool

Indicates all downloads were successful.

§timeout: HttpTimeout

Timeout management, both of timeout thresholds as well as whether or not our connection has timed out (and accompanying message if it has).

Note that timeout management is done manually here instead of in libcurl because we want to apply timeouts to an entire batch of operations, not any one particular single operation.

§updated_at: Cell<Instant>

Last time bytes were received.

§next_speed_check: Cell<Instant>

This is a slow-speed check. It is reset to now + timeout_duration every time at least threshold bytes are received. If the current time ever exceeds next_speed_check, then give up and report a timeout error.

§next_speed_check_bytes_threshold: Cell<u64>

This is the slow-speed threshold byte count. It starts at the configured threshold value (default 10), and is decremented by the number of bytes received in each chunk. If it is <= zero, the threshold has been met and data is being received fast enough not to trigger a timeout; reset next_speed_check and set this back to the configured threshold.

§_lock: CacheLock<'gctx>

Global filesystem lock to ensure only one Cargo is downloading at a time.

Implementations§

source§

impl<'a, 'gctx> Downloads<'a, 'gctx>

source

pub fn start(&mut self, id: PackageId) -> CargoResult<Option<&'a Package>>

Starts to download the package for the id specified.

Returns None if the package is queued up for download and will eventually be returned from wait_for_download. Returns Some(pkg) if the package is ready and doesn’t need to be downloaded.

source

fn start_inner(&mut self, id: PackageId) -> CargoResult<Option<&'a Package>>

source

pub fn remaining(&self) -> usize

Returns the number of crates that are still downloading.

source

pub fn wait(&mut self) -> CargoResult<&'a Package>

Blocks the current thread waiting for a package to finish downloading.

This method will wait for a previously enqueued package to finish downloading and return a reference to it after it’s done downloading.

§Panics

This function will panic if there are no remaining downloads.

source

fn enqueue(&mut self, dl: Download<'gctx>, handle: Easy) -> CargoResult<()>

source

fn wait_for_curl(&mut self) -> CargoResult<(usize, Result<(), Error>)>

Block, waiting for curl. Returns a token and a Result for that token (Ok means the download successfully finished).

source

fn add_sleepers(&mut self) -> CargoResult<()>

source

fn progress(&self, token: usize, total: u64, cur: u64) -> bool

source

fn tick(&self, why: WhyTick<'_>) -> CargoResult<()>

Trait Implementations§

source§

impl<'a, 'gctx> Drop for Downloads<'a, 'gctx>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'a, 'gctx> !Freeze for Downloads<'a, 'gctx>

§

impl<'a, 'gctx> !RefUnwindSafe for Downloads<'a, 'gctx>

§

impl<'a, 'gctx> !Send for Downloads<'a, 'gctx>

§

impl<'a, 'gctx> !Sync for Downloads<'a, 'gctx>

§

impl<'a, 'gctx> Unpin for Downloads<'a, 'gctx>

§

impl<'a, 'gctx> !UnwindSafe for Downloads<'a, 'gctx>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

source§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 440 bytes