Skip to main content

DownloadResult

Struct DownloadResult 

Source
pub struct DownloadResult<E, PullError, PushError>
where E: Executor + Send + Sync, PullError: Send + Unpin + 'static, PushError: Send + Unpin + 'static,
{ /* private fields */ }
Expand description

Handle to an active download session.

Cheaply cloneable shared handle. The underlying download keeps running as long as any clone is alive, and is cancelled only once the last clone is dropped. An explicit abort cancels immediately.

DownloadResult wraps Arc<DownloadResultInner> and exposes the session methods (abort, set_threads, set_min_chunk_size, is_aborted) and event_chain directly; each delegates to the inner value. There is intentionally no Deref impl — DownloadResultInner is private, so callers reach session state only through these methods.

The inner value is held in a ForceSend, a deliberately isolated workaround so the handle is Send even when it is built inside an async block (see that type’s module docs).

Completion is observed by draining the event stream: once the last sender is dropped (the download finished or was aborted) the receiver disconnects, so while result.recv().await.is_ok() {} awaits the session end. recv is the Send-safe form of that call; prefer it over result.event_chain().recv() in a tokio::spawned driver.

Implementations§

Source§

impl<E, PullError, PushError> DownloadResult<E, PullError, PushError>
where E: Executor + Send + Sync, PullError: Send + Unpin + 'static, PushError: Send + Unpin + 'static,

Source

pub fn event_chain( &self, ) -> &MAsyncRx<FlavorWrap<List<Event<PullError, PushError>>, RegistryDummy, RegistryMulti>>

Access the stream of Events emitted during the session.

The receiver closes once the last clone of this handle is dropped or the session is aborted, so draining it is a natural way to observe progress.

Source

pub fn recv( &self, ) -> impl Future<Output = Result<Event<PullError, PushError>, RecvError>> + Send

Await the next event, or Err once the session has ended.

Equivalent to self.event_chain().recv(), but returns impl Future + Send, so an enclosing async block that awaits it stays Send. Prefer this over event_chain().recv() in a tokio::spawned driver: the underlying RecvFuture is only Send through a hand-written impl that the async fn auto-trait leak check does not see through, so awaiting it inline reintroduces a spurious higher-ranked lifetime error. No allocation.

Source

pub fn abort(&self)

Cancel all workers immediately.

Safe to call multiple times and safe to call while other clones of the owning DownloadResult are still alive. The implicit drop-based cancellation (on the last clone) becomes a no-op once this has run.

Source

pub fn set_threads(&self, threads: usize)

Adjust the worker thread count of a running multi-threaded session.

The minimum chunk size used while growing is the session’s live value, set independently with set_min_chunk_size (or the configured value until then).

Growing spawns workers for ranges still waiting in the queue, or splits a range off the busiest running worker when nothing is waiting. Shrinking aborts the surplus workers and returns their ranges to the queue for the survivors to steal. No-op for single-threaded sessions, which have no task queue.

A session ends when its last worker exits, and it cannot be restarted: growing afterwards spawns nothing, because the workers’ shared channels are closed at that point. Shrinking is clamped to a minimum of one worker by the scheduler, so set_threads(0) keeps a single worker alive rather than ending the session. The session terminates only when that last (clamped) worker exits on its own.

This never touches the abort token: abort is terminal and cannot be undone by resizing, so is_aborted stays true across any later set_threads call, and any worker spawned by such a call observes the cancelled token and exits without pulling.

Source

pub fn set_min_chunk_size(&self, min_chunk_size: u64)

Set the minimum chunk size used when a worker next steals work.

Bounds how finely a running worker may split a range to take a share of a peer’s work: a range is only halved when at least min_chunk_size * 2 bytes remain. The new value takes effect on the next steal — there is no need to also call set_threads — and it is also the granularity used to split ranges the next time the pool grows.

A no-op for single-threaded sessions, which have no worker pool.

Source

pub fn is_aborted(&self) -> bool

Whether the session has been (or is being) cancelled.

Trait Implementations§

Source§

impl<E, PullError, PushError> Clone for DownloadResult<E, PullError, PushError>
where E: Executor + Send + Sync, PullError: Send + Unpin + 'static, PushError: Send + Unpin + 'static,

Source§

fn clone(&self) -> DownloadResult<E, PullError, PushError>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<E, PullError, PushError> Debug for DownloadResult<E, PullError, PushError>
where E: Executor + Send + Sync, PullError: Send + Unpin + 'static, PushError: Send + Unpin + 'static,

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<E, PullError, PushError> !RefUnwindSafe for DownloadResult<E, PullError, PushError>

§

impl<E, PullError, PushError> !UnwindSafe for DownloadResult<E, PullError, PushError>

§

impl<E, PullError, PushError> Freeze for DownloadResult<E, PullError, PushError>
where ForceSend<Arc<DownloadResultInner<E, PullError, PushError>>>: Freeze,

§

impl<E, PullError, PushError> Send for DownloadResult<E, PullError, PushError>
where ForceSend<Arc<DownloadResultInner<E, PullError, PushError>>>: Send,

§

impl<E, PullError, PushError> Sync for DownloadResult<E, PullError, PushError>
where ForceSend<Arc<DownloadResultInner<E, PullError, PushError>>>: Sync,

§

impl<E, PullError, PushError> Unpin for DownloadResult<E, PullError, PushError>
where ForceSend<Arc<DownloadResultInner<E, PullError, PushError>>>: Unpin,

§

impl<E, PullError, PushError> UnsafeUnpin for DownloadResult<E, PullError, PushError>
where ForceSend<Arc<DownloadResultInner<E, PullError, PushError>>>: UnsafeUnpin,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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