Skip to main content

DownloadPlan

Struct DownloadPlan 

Source
pub struct DownloadPlan { /* private fields */ }
Expand description

A prepared, not-yet-started download.

Produced by plan / plan_resume after the remote has been prefetched and the disk inspected. Holding one keeps the prefetch Response open so the first range request can reuse it; dropping one abandons the download without having touched the filesystem.

Implementations§

Source§

impl DownloadPlan

Source

pub const fn info(&self) -> &UrlInfo

Metadata resolved for the remote file: size, identity headers, and whether the server supports ranged (and therefore parallel) requests.

Source

pub const fn config(&self) -> &Config

The fully-resolved configuration this plan will run with.

Source

pub fn final_path(&self) -> &Path

Where the finished file is intended to land.

When overwrite is disabled the actual destination is uniquified at the very end, so the file may land on a name (1).ext variant instead; Event::Renamed carries the path it really landed on.

Source

pub fn tmp_path(&self) -> &Path

The .part file this plan inspected.

For ResumeOutcome::Resumable and ResumeOutcome::Mismatch this is the existing file that was examined. For a normal ResumeOutcome::Fresh it is the name that was free at probe time — because planning claims nothing, a concurrent download can take it first, in which case starting the plan moves on to the next free name. A manifest-driven Fresh plan instead reports the .part paired with that manifest.

Source

pub fn config_path(&self) -> &Path

The .fd state file paired with DownloadPlan::tmp_path.

Source

pub const fn resume_outcome(&self) -> &ResumeOutcome

What the disk probe found, and therefore what starting the plan will do.

Source

pub async fn start(self)

Run the plan as probed.

ResumeOutcome::Resumable continues from the saved progress and ResumeOutcome::Fresh downloads the whole file. A ResumeOutcome::Mismatch falls back to a fresh download, except for a plan made by plan_resume, where it is reported as Event::ResumeError and ends the run — that caller asked to continue one specific file, not to fetch it again.

Emits exactly one Event::Terminated as the last event on the channel.

Source

pub async fn start_fresh(self)

Ignore any resumable state and download the whole file again.

With overwrite enabled the existing .part is reused as scratch space and every byte is rewritten; otherwise a new, unclaimed .part name is taken so the existing one is left untouched.

Emits exactly one Event::Terminated as the last event on the channel.

Source

pub async fn start_forced_resume(self)

Continue from a ResumeOutcome::Mismatch state despite the failed validation.

This is only safe when the byte layout is unchanged, so the forced resume is refused unless the mismatch is limited to the identity headers (etag / last-modified) and both sides agree on the file size. A size change means the recorded ranges describe different bytes, and reusing them would splice two versions of the file together.

The .part is also measured against the recorded progress: a file shorter than the highest recorded offset is rejected with StateError::Truncated, because the sink would extend it with zeros over the missing span and never fetch those bytes.

A refusal is reported as Event::ResumeError followed by TerminationReason::Failed. Called on a plan that is not a mismatch, this behaves exactly like DownloadPlan::start.

Emits exactly one Event::Terminated as the last event on the channel.

Auto Trait Implementations§

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.

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

Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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