Struct cargo::core::package::Downloads

source ·
pub struct Downloads<'a, 'cfg> {
Show 17 fields set: &'a PackageSet<'cfg>, pending: HashMap<usize, (Download<'cfg>, EasyHandle)>, pending_ids: HashSet<PackageId>, sleeping: SleepTracker<(Download<'cfg>, Easy)>, results: Vec<(usize, Result<(), Error>)>, next: usize, progress: RefCell<Option<Progress<'cfg>>>, 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: PackageCacheLock<'cfg>,
}
Expand description

Helper for downloading crates.

Fields§

§set: &'a PackageSet<'cfg>§pending: HashMap<usize, (Download<'cfg>, 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<'cfg>, 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<'cfg>>>

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: PackageCacheLock<'cfg>

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

Implementations§

source§

impl<'a, 'cfg> Downloads<'a, 'cfg>

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<'cfg>, 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, 'cfg> Drop for Downloads<'a, 'cfg>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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.

source§

impl<T> Instrument for T

source§

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

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

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 Twhere 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.

source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

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

§

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 Twhere U: TryFrom<T>,

§

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 Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

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
source§

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: 432 bytes