Skip to main content

Download

Struct Download 

Source
struct Download {
    job: Job,
    headers: Arc<[(HeaderName, HeaderValue)]>,
    agent: Agent,
    connect: Sender<Event>,
    next_connection: usize,
    parts: Vec<Part>,
    partial: Option<Partial>,
    total: Option<u64>,
    speed: u64,
    paused: bool,
    meter: SpeedMeter,
    last_report: Option<Instant>,
}
Expand description

A download in progress, as its own thread sees it.

Fields§

§job: Job§headers: Arc<[(HeaderName, HeaderValue)]>§agent: Agent§connect: Sender<Event>§next_connection: usize

The id the next connection gets.

§parts: Vec<Part>

In the order they come in the file, which they cover between them.

§partial: Option<Partial>

The file being written, once a server has answered.

§total: Option<u64>

The whole file’s length, when the server said.

§speed: u64§paused: bool§meter: SpeedMeter§last_report: Option<Instant>

Implementations§

Source§

impl Download

Source

fn follow( &mut self, events: &Receiver<Event>, report: &impl Fn(Report) -> Result<(), Abandoned>, ) -> Result<Report, Stopped>

Handles events until the file is saved, giving the report that says so, or the download stops.

Source

fn next_event( &mut self, events: &Receiver<Event>, report: &impl Fn(Report) -> Result<(), Abandoned>, ) -> Result<Event, Stopped>

Waits for the next event, trying again each part whose wait to retry ends first.

Source

fn retry_due( &mut self, report: &impl Fn(Report) -> Result<(), Abandoned>, ) -> Result<(), Abandoned>

Starts a connection again for each part whose wait to retry is over, saying the download is under way again if nothing was.

Source

fn is_waiting(&self) -> bool

Whether no connection is running, only parts waiting to retry.

Source

fn part_of(&self, id: usize) -> Option<usize>

Which part connection id is fetching, unless it has been stopped.

Source

fn dial(&mut self, index: usize)

Starts a connection for what isn’t saved yet of the part at index. The whole file is asked for as a range while the download may still split it, so the answer says whether the server can send parts.

Source

fn progress(&self) -> Progress

Source

fn pause( &mut self, report: &impl Fn(Report) -> Result<(), Abandoned>, ) -> Result<(), Abandoned>

Stops every connection, keeping what they saved, unless already paused.

Source

fn resume( &mut self, report: &impl Fn(Report) -> Result<(), Abandoned>, ) -> Result<Option<Report>, Stopped>

Carries on after a pause with a new connection for each part not yet saved, unless the file was complete, when it is saved at once.

Source

fn is_complete(&self) -> bool

Source

fn answered(&mut self, index: usize, answer: &Answer) -> Result<(), Stopped>

Opens the file for the connection the server answered, from where its body begins: a new partial file the first time, when the file may also be split into parts.

Source

fn create(&mut self, answer: &Answer) -> Result<File, Stopped>

Creates the partial file for the first answer, and splits the file into parts when the download may and the server can send them, starting a connection for each part after the first.

Source

fn partial_path(&self) -> &Path

Source

fn wrote( &mut self, index: usize, bytes: u64, report: &impl Fn(Report) -> Result<(), Abandoned>, ) -> Result<(), Abandoned>

Source

fn ended( &mut self, index: usize, ended: Result<(), ConnectionError>, report: &impl Fn(Report) -> Result<(), Abandoned>, ) -> Result<Option<Report>, Stopped>

Handles the end of the part at index’s connection: makes sure what it wrote is on disk, and saves the file once every part is, giving the report that says so. A failure that may pass is tried again later while retries are left.

Source

fn retry_later( &mut self, index: usize, error: ConnectionError, report: &impl Fn(Report) -> Result<(), Abandoned>, ) -> Result<(), Stopped>

Stops the part at index’s failed connection, keeping what it saved, and tries it again after a wait, saying so when nothing else is downloading.

§Errors

The failure, when it can’t pass or no retries are left.

Source

fn save(&mut self) -> Result<Report, Stopped>

Gives the file its name.

Source

fn clean_up(&mut self, stopped: Stopped) -> Stopped

Stops every connection and removes what they wrote, saying why the download stopped.

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