Skip to content

Commit 7f68b55

Browse files
committed
Inline dist::notifications::Notification variants into top-level Notification
1 parent 607a963 commit 7f68b55

File tree

14 files changed

+204
-293
lines changed

14 files changed

+204
-293
lines changed

src/cli/common.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use tracing_subscriber::{EnvFilter, Registry, reload::Handle};
1616
use crate::{
1717
cli::download_tracker::DownloadTracker,
1818
config::Cfg,
19-
dist::{TargetTriple, ToolchainDesc, notifications as dist_notifications},
19+
dist::{TargetTriple, ToolchainDesc},
2020
errors::RustupError,
2121
install::UpdateStatus,
2222
notifications::Notification,
@@ -139,10 +139,7 @@ impl Notifier {
139139
return;
140140
}
141141

142-
if let Notification::Install(dist_notifications::Notification::Utils(
143-
util_notifications::Notification::SetDefaultBufferSize(_),
144-
)) = &n
145-
{
142+
if let Notification::Utils(util_notifications::Notification::SetDefaultBufferSize(_)) = &n {
146143
if *self.ram_notice_shown.borrow() {
147144
return;
148145
} else {

src/cli/download_tracker.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use indicatif::{MultiProgress, ProgressBar, ProgressDrawTarget, ProgressStyle};
22
use std::collections::HashMap;
33
use std::time::{Duration, Instant};
44

5-
use crate::dist::Notification as In;
65
use crate::notifications::Notification;
76
use crate::process::Process;
87
use crate::utils::Notification as Un;
@@ -40,36 +39,33 @@ impl DownloadTracker {
4039

4140
pub(crate) fn handle_notification(&mut self, n: &Notification<'_>) -> bool {
4241
match *n {
43-
Notification::Install(In::Utils(Un::DownloadContentLengthReceived(
44-
content_len,
45-
url,
46-
))) => {
42+
Notification::Utils(Un::DownloadContentLengthReceived(content_len, url)) => {
4743
if let Some(url) = url {
4844
self.content_length_received(content_len, url);
4945
}
5046
true
5147
}
52-
Notification::Install(In::Utils(Un::DownloadDataReceived(data, url))) => {
48+
Notification::Utils(Un::DownloadDataReceived(data, url)) => {
5349
if let Some(url) = url {
5450
self.data_received(data.len(), url);
5551
}
5652
true
5753
}
58-
Notification::Install(In::Utils(Un::DownloadFinished(url))) => {
54+
Notification::Utils(Un::DownloadFinished(url)) => {
5955
if let Some(url) = url {
6056
self.download_finished(url);
6157
}
6258
true
6359
}
64-
Notification::Install(In::Utils(Un::DownloadFailed(url))) => {
60+
Notification::Utils(Un::DownloadFailed(url)) => {
6561
self.download_failed(url);
6662
false
6763
}
68-
Notification::Install(In::DownloadingComponent(component, _, _, url)) => {
64+
Notification::DownloadingComponent(component, _, _, url) => {
6965
self.create_progress_bar(component.to_owned(), url.to_owned());
7066
true
7167
}
72-
Notification::Install(In::RetryingDownload(url)) => {
68+
Notification::RetryingDownload(url) => {
7369
self.retrying_download(url);
7470
true
7571
}

src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ impl<'a> Cfg<'a> {
330330
/// construct a download configuration
331331
pub(crate) fn download_cfg(
332332
&'a self,
333-
notify_handler: &'a dyn Fn(crate::dist::Notification<'_>),
333+
notify_handler: &'a dyn Fn(Notification<'_>),
334334
) -> DownloadCfg<'a> {
335335
DownloadCfg {
336336
dist_root: &self.dist_root_url,

src/dist/component/tests.rs

Lines changed: 25 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use std::io::Write;
33
use std::path::PathBuf;
44

55
use crate::dist::DEFAULT_DIST_SERVER;
6-
use crate::dist::Notification;
76
use crate::dist::component::Transaction;
87
use crate::dist::prefix::InstallPrefix;
98
use crate::dist::temp;
@@ -24,9 +23,8 @@ fn add_file() {
2423
Box::new(|_| ()),
2524
);
2625

27-
let notify = |_: Notification<'_>| ();
2826
let tp = TestProcess::default();
29-
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &notify, &tp.process);
27+
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &|_| (), &tp.process);
3028

3129
let mut file = tx.add_file("c", PathBuf::from("foo/bar")).unwrap();
3230
write!(file, "test").unwrap();
@@ -53,9 +51,8 @@ fn add_file_then_rollback() {
5351
Box::new(|_| ()),
5452
);
5553

56-
let notify = |_: Notification<'_>| ();
5754
let tp = TestProcess::default();
58-
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &notify, &tp.process);
55+
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &|_| (), &tp.process);
5956

6057
tx.add_file("c", PathBuf::from("foo/bar")).unwrap();
6158
drop(tx);
@@ -76,9 +73,8 @@ fn add_file_that_exists() {
7673

7774
let prefix = InstallPrefix::from(prefixdir.path());
7875

79-
let notify = |_: Notification<'_>| ();
8076
let tp = TestProcess::default();
81-
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &notify, &tp.process);
77+
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &|_| (), &tp.process);
8278

8379
fs::create_dir_all(prefixdir.path().join("foo")).unwrap();
8480
utils::write_file("", &prefixdir.path().join("foo/bar"), "").unwrap();
@@ -108,9 +104,8 @@ fn copy_file() {
108104

109105
let prefix = InstallPrefix::from(prefixdir.path());
110106

111-
let notify = |_: Notification<'_>| ();
112107
let tp = TestProcess::default();
113-
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &notify, &tp.process);
108+
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &|_| (), &tp.process);
114109

115110
let srcpath = srcdir.path().join("bar");
116111
utils::write_file("", &srcpath, "").unwrap();
@@ -136,9 +131,8 @@ fn copy_file_then_rollback() {
136131

137132
let prefix = InstallPrefix::from(prefixdir.path());
138133

139-
let notify = |_: Notification<'_>| ();
140134
let tp = TestProcess::default();
141-
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &notify, &tp.process);
135+
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &|_| (), &tp.process);
142136

143137
let srcpath = srcdir.path().join("bar");
144138
utils::write_file("", &srcpath, "").unwrap();
@@ -164,9 +158,8 @@ fn copy_file_that_exists() {
164158

165159
let prefix = InstallPrefix::from(prefixdir.path());
166160

167-
let notify = |_: Notification<'_>| ();
168161
let tp = TestProcess::default();
169-
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &notify, &tp.process);
162+
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &|_| (), &tp.process);
170163

171164
let srcpath = srcdir.path().join("bar");
172165
utils::write_file("", &srcpath, "").unwrap();
@@ -201,9 +194,8 @@ fn copy_dir() {
201194

202195
let prefix = InstallPrefix::from(prefixdir.path());
203196

204-
let notify = |_: Notification<'_>| ();
205197
let tp = TestProcess::default();
206-
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &notify, &tp.process);
198+
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &|_| (), &tp.process);
207199

208200
let srcpath1 = srcdir.path().join("foo");
209201
let srcpath2 = srcdir.path().join("bar/baz");
@@ -236,9 +228,8 @@ fn copy_dir_then_rollback() {
236228

237229
let prefix = InstallPrefix::from(prefixdir.path());
238230

239-
let notify = |_: Notification<'_>| ();
240231
let tp = TestProcess::default();
241-
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &notify, &tp.process);
232+
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &|_| (), &tp.process);
242233

243234
let srcpath1 = srcdir.path().join("foo");
244235
let srcpath2 = srcdir.path().join("bar/baz");
@@ -271,9 +262,8 @@ fn copy_dir_that_exists() {
271262

272263
let prefix = InstallPrefix::from(prefixdir.path());
273264

274-
let notify = |_: Notification<'_>| ();
275265
let tp = TestProcess::default();
276-
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &notify, &tp.process);
266+
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &|_| (), &tp.process);
277267

278268
fs::create_dir_all(prefix.path().join("a")).unwrap();
279269

@@ -303,9 +293,8 @@ fn remove_file() {
303293

304294
let prefix = InstallPrefix::from(prefixdir.path());
305295

306-
let notify = |_: Notification<'_>| ();
307296
let tp = TestProcess::default();
308-
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &notify, &tp.process);
297+
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &|_| (), &tp.process);
309298

310299
let filepath = prefixdir.path().join("foo");
311300
utils::write_file("", &filepath, "").unwrap();
@@ -329,9 +318,8 @@ fn remove_file_then_rollback() {
329318

330319
let prefix = InstallPrefix::from(prefixdir.path());
331320

332-
let notify = |_: Notification<'_>| ();
333321
let tp = TestProcess::default();
334-
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &notify, &tp.process);
322+
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &|_| (), &tp.process);
335323

336324
let filepath = prefixdir.path().join("foo");
337325
utils::write_file("", &filepath, "").unwrap();
@@ -355,9 +343,8 @@ fn remove_file_that_not_exists() {
355343

356344
let prefix = InstallPrefix::from(prefixdir.path());
357345

358-
let notify = |_: Notification<'_>| ();
359346
let tp = TestProcess::default();
360-
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &notify, &tp.process);
347+
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &|_| (), &tp.process);
361348

362349
let err = tx.remove_file("c", PathBuf::from("foo")).unwrap_err();
363350

@@ -383,9 +370,8 @@ fn remove_dir() {
383370

384371
let prefix = InstallPrefix::from(prefixdir.path());
385372

386-
let notify = |_: Notification<'_>| ();
387373
let tp = TestProcess::default();
388-
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &notify, &tp.process);
374+
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &|_| (), &tp.process);
389375

390376
let filepath = prefixdir.path().join("foo/bar");
391377
fs::create_dir_all(filepath.parent().unwrap()).unwrap();
@@ -410,9 +396,8 @@ fn remove_dir_then_rollback() {
410396

411397
let prefix = InstallPrefix::from(prefixdir.path());
412398

413-
let notify = |_: Notification<'_>| ();
414399
let tp = TestProcess::default();
415-
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &notify, &tp.process);
400+
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &|_| (), &tp.process);
416401

417402
let filepath = prefixdir.path().join("foo/bar");
418403
fs::create_dir_all(filepath.parent().unwrap()).unwrap();
@@ -437,9 +422,8 @@ fn remove_dir_that_not_exists() {
437422

438423
let prefix = InstallPrefix::from(prefixdir.path());
439424

440-
let notify = |_: Notification<'_>| ();
441425
let tp = TestProcess::default();
442-
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &notify, &tp.process);
426+
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &|_| (), &tp.process);
443427

444428
let err = tx.remove_dir("c", PathBuf::from("foo")).unwrap_err();
445429

@@ -465,9 +449,8 @@ fn write_file() {
465449

466450
let prefix = InstallPrefix::from(prefixdir.path());
467451

468-
let notify = |_: Notification<'_>| ();
469452
let tp = TestProcess::default();
470-
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &notify, &tp.process);
453+
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &|_| (), &tp.process);
471454

472455
let content = "hi".to_string();
473456
tx.write_file("c", PathBuf::from("foo/bar"), content.clone())
@@ -493,9 +476,8 @@ fn write_file_then_rollback() {
493476

494477
let prefix = InstallPrefix::from(prefixdir.path());
495478

496-
let notify = |_: Notification<'_>| ();
497479
let tp = TestProcess::default();
498-
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &notify, &tp.process);
480+
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &|_| (), &tp.process);
499481

500482
let content = "hi".to_string();
501483
tx.write_file("c", PathBuf::from("foo/bar"), content)
@@ -518,9 +500,8 @@ fn write_file_that_exists() {
518500

519501
let prefix = InstallPrefix::from(prefixdir.path());
520502

521-
let notify = |_: Notification<'_>| ();
522503
let tp = TestProcess::default();
523-
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &notify, &tp.process);
504+
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &|_| (), &tp.process);
524505

525506
let content = "hi".to_string();
526507
utils_raw::write_file(&prefix.path().join("a"), &content).unwrap();
@@ -550,9 +531,8 @@ fn modify_file_that_not_exists() {
550531

551532
let prefix = InstallPrefix::from(prefixdir.path());
552533

553-
let notify = |_: Notification<'_>| ();
554534
let tp = TestProcess::default();
555-
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &notify, &tp.process);
535+
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &|_| (), &tp.process);
556536

557537
tx.modify_file(PathBuf::from("foo/bar")).unwrap();
558538
tx.commit();
@@ -575,9 +555,8 @@ fn modify_file_that_exists() {
575555

576556
let prefix = InstallPrefix::from(prefixdir.path());
577557

578-
let notify = |_: Notification<'_>| ();
579558
let tp = TestProcess::default();
580-
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &notify, &tp.process);
559+
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &|_| (), &tp.process);
581560

582561
let path = prefix.path().join("foo");
583562
utils_raw::write_file(&path, "wow").unwrap();
@@ -600,9 +579,8 @@ fn modify_file_that_not_exists_then_rollback() {
600579

601580
let prefix = InstallPrefix::from(prefixdir.path());
602581

603-
let notify = |_: Notification<'_>| ();
604582
let tp = TestProcess::default();
605-
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &notify, &tp.process);
583+
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &|_| (), &tp.process);
606584

607585
tx.modify_file(PathBuf::from("foo/bar")).unwrap();
608586
drop(tx);
@@ -623,9 +601,8 @@ fn modify_file_that_exists_then_rollback() {
623601

624602
let prefix = InstallPrefix::from(prefixdir.path());
625603

626-
let notify = |_: Notification<'_>| ();
627604
let tp = TestProcess::default();
628-
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &notify, &tp.process);
605+
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &|_| (), &tp.process);
629606

630607
let path = prefix.path().join("foo");
631608
utils_raw::write_file(&path, "wow").unwrap();
@@ -651,9 +628,8 @@ fn modify_twice_then_rollback() {
651628

652629
let prefix = InstallPrefix::from(prefixdir.path());
653630

654-
let notify = |_: Notification<'_>| ();
655631
let tp = TestProcess::default();
656-
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &notify, &tp.process);
632+
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &|_| (), &tp.process);
657633

658634
let path = prefix.path().join("foo");
659635
utils_raw::write_file(&path, "wow").unwrap();
@@ -679,9 +655,8 @@ fn do_multiple_op_transaction(rollback: bool) {
679655

680656
let prefix = InstallPrefix::from(prefixdir.path());
681657

682-
let notify = |_: Notification<'_>| ();
683658
let tp = TestProcess::default();
684-
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &notify, &tp.process);
659+
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &|_| (), &tp.process);
685660

686661
// copy_file
687662
let relpath1 = PathBuf::from("bin/rustc");
@@ -781,9 +756,8 @@ fn rollback_failure_keeps_going() {
781756

782757
let prefix = InstallPrefix::from(prefixdir.path());
783758

784-
let notify = |_: Notification<'_>| ();
785759
let tp = TestProcess::default();
786-
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &notify, &tp.process);
760+
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &|_| (), &tp.process);
787761

788762
write!(tx.add_file("", PathBuf::from("foo")).unwrap(), "").unwrap();
789763
write!(tx.add_file("", PathBuf::from("bar")).unwrap(), "").unwrap();

src/dist/component/transaction.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ use std::path::{Path, PathBuf};
1414

1515
use anyhow::{Context, Result, anyhow};
1616

17-
use crate::dist::notifications::*;
1817
use crate::dist::prefix::InstallPrefix;
1918
use crate::dist::temp;
2019
use crate::errors::*;
20+
use crate::notifications::Notification;
2121
use crate::process::Process;
2222
use crate::utils;
2323

src/dist/download.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ use anyhow::{Context, Result, anyhow};
66
use sha2::{Digest, Sha256};
77
use url::Url;
88

9-
use crate::dist::notifications::*;
109
use crate::dist::temp;
1110
use crate::download::download_file;
1211
use crate::download::download_file_with_resume;
1312
use crate::errors::*;
13+
use crate::notifications::Notification;
1414
use crate::process::Process;
1515
use crate::utils;
1616

0 commit comments

Comments
 (0)