fast_down_api/lib.rs
1#![doc = include_str!("../README.md")]
2
3mod config;
4mod core;
5mod event;
6pub(crate) mod utils;
7
8pub use config::*;
9pub use core::*;
10pub use event::*;
11
12pub use fast_down;
13
14pub use tokio_util::sync::CancellationToken;
15
16/// Sender half of the event channel, used to push [`Event`]s from the download task.
17pub type Tx = crossfire::MTx<crossfire::mpmc::List<Event>>;
18/// Receiver half of the event channel, used to receive [`Event`]s from the download task.
19pub type Rx = crossfire::MAsyncRx<crossfire::mpmc::List<Event>>;
20
21/// Create a new unbounded event channel for receiving download progress events.
22///
23/// Returns a sender (`Tx`) and receiver (`Rx`) pair.
24#[must_use]
25pub fn create_channel() -> (Tx, Rx) {
26 crossfire::mpmc::unbounded_async()
27}
28
29/// Create a new [`CancellationToken`] for cooperative cancellation of a download.
30///
31/// Pass the returned token to [`download`] (or a related entry
32/// point) and call
33/// [`CancellationToken::cancel`](tokio_util::sync::CancellationToken::cancel) to
34/// abort the in-flight download.
35#[must_use]
36pub fn create_cancellation_token() -> CancellationToken {
37 CancellationToken::new()
38}