pub struct DownloadQueue { /* private fields */ }Expand description
Synchronous download queue that tracks tasks and enforces concurrency limits.
This is a pure data structure — it does not perform I/O. The caller is
responsible for taking tasks via take_next, spawning async downloads,
and updating task state when downloads progress or complete.
Implementations§
Source§impl DownloadQueue
impl DownloadQueue
Sourcepub fn enqueue(
&mut self,
url: String,
dest: PathBuf,
expected_hash: Option<u64>,
meta: DownloadMeta,
) -> usize
pub fn enqueue( &mut self, url: String, dest: PathBuf, expected_hash: Option<u64>, meta: DownloadMeta, ) -> usize
Add a task to the queue. Returns the assigned task ID.
Sourcepub fn load_from_sidecars(
download_dir: &Path,
max_concurrent: usize,
) -> Result<Self>
pub fn load_from_sidecars( download_dir: &Path, max_concurrent: usize, ) -> Result<Self>
Rebuild a queue from persisted .meta sidecars in a download directory.
Active downloads are restored as paused because no transport is running after process startup. Complete entries are restored only when the downloaded file still exists.
Sourcepub fn save_sidecars(&mut self) -> Result<()>
pub fn save_sidecars(&mut self) -> Result<()>
Persist every task’s .meta sidecar beside its destination file.
Sourcepub fn active_count(&self) -> usize
pub fn active_count(&self) -> usize
Number of currently active downloads.
Sourcepub fn pending(&self) -> Vec<&DownloadTask>
pub fn pending(&self) -> Vec<&DownloadTask>
All tasks in the Queued state, ready to be started.
Sourcepub fn take_next(&mut self) -> Option<&mut DownloadTask>
pub fn take_next(&mut self) -> Option<&mut DownloadTask>
Get the next Queued task if the concurrency limit has not been reached.
Transitions the task to Active and returns a mutable reference so the
caller can spawn the download.
Sourcepub fn get(&self, id: usize) -> Option<&DownloadTask>
pub fn get(&self, id: usize) -> Option<&DownloadTask>
Look up a task by ID.
Sourcepub fn get_mut(&mut self, id: usize) -> Option<&mut DownloadTask>
pub fn get_mut(&mut self, id: usize) -> Option<&mut DownloadTask>
Look up a task by ID (mutable).
Sourcepub fn all(&self) -> &[DownloadTask]
pub fn all(&self) -> &[DownloadTask]
View all tracked tasks in insertion order.
Auto Trait Implementations§
impl Freeze for DownloadQueue
impl RefUnwindSafe for DownloadQueue
impl Send for DownloadQueue
impl Sync for DownloadQueue
impl Unpin for DownloadQueue
impl UnsafeUnpin for DownloadQueue
impl UnwindSafe for DownloadQueue
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more