Skip to main content

Downloads

Struct Downloads 

Source
pub struct Downloads<T> {
    pub(crate) waker: Arc<dyn Waker>,
    pub(crate) sender: Sender<(DownloadId, Report)>,
    pub(crate) receiver: Receiver<(DownloadId, Report)>,
    pub(crate) running: RefCell<HashMap<DownloadId, Running<T>>>,
}
Expand description

The downloads an app has running, and the channel their reports arrive on.

Fields§

§waker: Arc<dyn Waker>§sender: Sender<(DownloadId, Report)>§receiver: Receiver<(DownloadId, Report)>§running: RefCell<HashMap<DownloadId, Running<T>>>

Implementations§

Source§

impl<T> Downloads<T>

Source

pub fn new(waker: Arc<dyn Waker>) -> Self

waker asks the UI thread to call Downloads::receive.

Source

pub fn start(&self, request: Request<T>)

Source

pub fn command(&self, id: &str, command: DownloadCommand)

Asks the download whose id id shows to do command. An id of no running download, such as one that has just finished, asks nothing.

Source

pub fn receive<E>( &self, follow: impl FnMut(&mut T) -> bool, apply: impl FnMut(&T, &Report) -> Result<(), E>, ) -> Result<(), E>

Hands each report that has arrived to apply with where it goes, forgetting downloads that have finished. follow first moves a download’s targets to where its item is now, or says the app no longer holds it, which cancels it. Stops at the first error, leaving later reports queued.

§Errors

The first error apply returns.

§Panics

When a report arrives from a download this doesn’t know, which can’t happen: each is forgotten only after its last report.

Source

pub fn cancel_unheld(&self, follow: impl FnMut(&mut T) -> bool)

Cancels each download whose item follow no longer finds, after the app’s code changed state, and keeps the rest’s targets where their items are.

Source

pub(crate) fn next_report(&self) -> Option<(DownloadId, Report)>

Trait Implementations§

Source§

impl<T> Debug for Downloads<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Drop for Downloads<T>

The app is going, as when nf dev replaces its program: each download stops and removes its partial file before this returns. A download’s thread never waits on the network, only on its events, so this is quick.

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl<T> !Freeze for Downloads<T>

§

impl<T> !RefUnwindSafe for Downloads<T>

§

impl<T> !Sync for Downloads<T>

§

impl<T> !UnwindSafe for Downloads<T>

§

impl<T> Send for Downloads<T>
where T: Send,

§

impl<T> Unpin for Downloads<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for Downloads<T>

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.