Skip to content

Commit 6476b50

Browse files
downloader: Fix exports and add prelude module
1 parent d9691ff commit 6476b50

File tree

4 files changed

+28
-25
lines changed

4 files changed

+28
-25
lines changed

crates/download-manager/src/download.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub struct Download {
2121
}
2222

2323
impl Download {
24-
pub fn new(
24+
pub(crate) fn new(
2525
id: DownloadID,
2626
progress: watch::Receiver<Progress>,
2727
events: broadcast::Receiver<DownloadEvent>,

crates/download-manager/src/download_manager.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,23 @@ mod error;
44
mod events;
55
mod request;
66
mod scheduler;
7+
pub mod prelude {
8+
pub use crate::{
9+
context::DownloadID,
10+
download::{Download, DownloadResult},
11+
error::DownloadError,
12+
events::{DownloadEvent, Progress},
13+
request::Request,
14+
};
15+
}
716

817
use crate::{
918
context::Context,
1019
request::RequestBuilder,
1120
scheduler::{Scheduler, SchedulerCmd},
1221
};
13-
pub use crate::{
14-
context::DownloadID,
15-
download::{Download, DownloadResult},
16-
error::DownloadError,
17-
events::{DownloadEvent, Progress},
18-
request::Request,
19-
};
2022
use futures_core::Stream;
23+
use prelude::*;
2124
use reqwest::Url;
2225
use std::{
2326
path::Path,

crates/download-manager/src/events.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pub struct Progress {
6262
}
6363

6464
impl Progress {
65-
pub fn new(total_bytes: Option<u64>) -> Self {
65+
pub(crate) fn new(total_bytes: Option<u64>) -> Self {
6666
let now = Instant::now();
6767
Progress {
6868
bytes_downloaded: 0,
@@ -79,17 +79,17 @@ impl Progress {
7979
}
8080
}
8181

82-
pub fn with_sample_interval(mut self, min_sample_interval: Duration) -> Self {
82+
pub(crate) fn with_sample_interval(mut self, min_sample_interval: Duration) -> Self {
8383
self.min_sample_interval = min_sample_interval;
8484
self
8585
}
8686

87-
pub fn with_sample_bytes(mut self, min_sample_bytes: u64) -> Self {
87+
pub(crate) fn with_sample_bytes(mut self, min_sample_bytes: u64) -> Self {
8888
self.min_sample_bytes = min_sample_bytes;
8989
self
9090
}
9191

92-
pub fn with_ema_alpha(mut self, ema_alpha: f64) -> Self {
92+
pub(crate) fn with_ema_alpha(mut self, ema_alpha: f64) -> Self {
9393
self.ema_alpha = ema_alpha;
9494
self
9595
}
@@ -122,7 +122,7 @@ impl Progress {
122122
}
123123
}
124124

125-
pub fn update(&mut self, chunk_len: u64) -> bool {
125+
pub(crate) fn update(&mut self, chunk_len: u64) -> bool {
126126
let now = Instant::now();
127127
self.bytes_downloaded += chunk_len;
128128
self.updated_at = now;
@@ -153,7 +153,7 @@ impl Progress {
153153
false
154154
}
155155

156-
pub fn force_update(&mut self) {
156+
pub(crate) fn force_update(&mut self) {
157157
let now = Instant::now();
158158
let dt = now.duration_since(self.last_sample_at);
159159
let byte_delta = self.bytes_downloaded - self.last_sample_bytes;

crates/download-manager/src/scheduler.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ static BACKOFF_STRATEGY: ExponentialBackoff = ExponentialBackoff {
3636
max_delay: Duration::from_secs(10),
3737
};
3838

39-
pub enum SchedulerCmd {
39+
pub(crate) enum SchedulerCmd {
4040
Enqueue {
4141
request: Request,
4242
result_tx: oneshot::Sender<Result<DownloadResult, DownloadError>>,
@@ -46,14 +46,14 @@ pub enum SchedulerCmd {
4646
},
4747
}
4848

49-
pub enum WorkerMsg {
49+
enum WorkerMsg {
5050
Finish {
5151
id: DownloadID,
5252
result: Result<DownloadResult, DownloadError>,
5353
},
5454
}
5555

56-
pub struct Scheduler {
56+
pub(crate) struct Scheduler {
5757
ctx: Arc<Context>,
5858
tracker: TaskTracker,
5959

@@ -85,7 +85,7 @@ impl Scheduler {
8585
}
8686
}
8787

88-
pub fn schedule(&mut self, job: Job) {
88+
fn schedule(&mut self, job: Job) {
8989
let request = &job.request;
9090
let id = job.id();
9191
request.emit(DownloadEvent::Queued {
@@ -222,25 +222,25 @@ pub(crate) struct Job {
222222
}
223223

224224
impl Job {
225-
pub fn id(&self) -> DownloadID {
225+
fn id(&self) -> DownloadID {
226226
self.request.id()
227227
}
228228

229-
pub fn send_result(self, result: Result<DownloadResult, DownloadError>) {
229+
fn send_result(self, result: Result<DownloadResult, DownloadError>) {
230230
if let Some(result_tx) = self.result {
231231
let _ = result_tx.send(result);
232232
}
233233
}
234234

235-
pub fn fail(self, error: DownloadError) {
235+
fn fail(self, error: DownloadError) {
236236
self.request.emit(DownloadEvent::Failed {
237237
id: self.id(),
238238
error: error.to_string(),
239239
});
240240
self.send_result(Err(error));
241241
}
242242

243-
pub fn finish(self, result: DownloadResult) {
243+
fn finish(self, result: DownloadResult) {
244244
self.request.emit(DownloadEvent::Completed {
245245
id: self.id(),
246246
path: result.path.clone(),
@@ -249,23 +249,23 @@ impl Job {
249249
self.send_result(Ok(result))
250250
}
251251

252-
pub fn retry(&self, delay: Duration) {
252+
fn retry(&self, delay: Duration) {
253253
self.request.emit(DownloadEvent::Retrying {
254254
id: self.id(),
255255
attempt: self.attempt,
256256
next_delay_ms: delay.as_millis() as u64,
257257
});
258258
}
259259

260-
pub fn cancel(self) {
260+
fn cancel(self) {
261261
self.request.cancel_token.cancel();
262262
self.request
263263
.emit(DownloadEvent::Cancelled { id: self.id() });
264264
self.send_result(Err(DownloadError::Cancelled))
265265
}
266266
}
267267

268-
pub async fn run(request: Arc<Request>, ctx: Arc<Context>, worker_tx: mpsc::Sender<WorkerMsg>) {
268+
async fn run(request: Arc<Request>, ctx: Arc<Context>, worker_tx: mpsc::Sender<WorkerMsg>) {
269269
let result = attempt_download(request.as_ref(), ctx.client.clone()).await;
270270

271271
let _ = worker_tx

0 commit comments

Comments
 (0)