Skip to content

Commit 8e90e40

Browse files
committed
Inline utils::notifications::Notification variants into top-level Notification
1 parent 7f68b55 commit 8e90e40

File tree

14 files changed

+104
-146
lines changed

14 files changed

+104
-146
lines changed

src/cli/common.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use crate::{
2222
notifications::Notification,
2323
process::{Process, terminalsource},
2424
toolchain::{LocalToolchainName, Toolchain, ToolchainName},
25-
utils::{self, notifications as util_notifications, notify::NotificationLevel},
25+
utils::{self, notify::NotificationLevel},
2626
};
2727

2828
pub(crate) const WARN_COMPLETE_PROFILE: &str = "downloading with complete profile isn't recommended unless you are a developer of the rust language";
@@ -139,7 +139,7 @@ impl Notifier {
139139
return;
140140
}
141141

142-
if let Notification::Utils(util_notifications::Notification::SetDefaultBufferSize(_)) = &n {
142+
if let Notification::SetDefaultBufferSize(_) = &n {
143143
if *self.ram_notice_shown.borrow() {
144144
return;
145145
} else {

src/cli/download_tracker.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use std::time::{Duration, Instant};
44

55
use crate::notifications::Notification;
66
use crate::process::Process;
7-
use crate::utils::Notification as Un;
87

98
/// Tracks download progress and displays information about it to a terminal.
109
///
@@ -39,25 +38,25 @@ impl DownloadTracker {
3938

4039
pub(crate) fn handle_notification(&mut self, n: &Notification<'_>) -> bool {
4140
match *n {
42-
Notification::Utils(Un::DownloadContentLengthReceived(content_len, url)) => {
41+
Notification::DownloadContentLengthReceived(content_len, url) => {
4342
if let Some(url) = url {
4443
self.content_length_received(content_len, url);
4544
}
4645
true
4746
}
48-
Notification::Utils(Un::DownloadDataReceived(data, url)) => {
47+
Notification::DownloadDataReceived(data, url) => {
4948
if let Some(url) = url {
5049
self.data_received(data.len(), url);
5150
}
5251
true
5352
}
54-
Notification::Utils(Un::DownloadFinished(url)) => {
53+
Notification::DownloadFinished(url) => {
5554
if let Some(url) = url {
5655
self.download_finished(url);
5756
}
5857
true
5958
}
60-
Notification::Utils(Un::DownloadFailed(url)) => {
59+
Notification::DownloadFailed(url) => {
6160
self.download_failed(url);
6261
false
6362
}

src/cli/self_update.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ use crate::{
6666
DistributableToolchain, MaybeOfficialToolchainName, ResolvableToolchainName, Toolchain,
6767
ToolchainName,
6868
},
69-
utils::{self, Notification},
69+
notifications::Notification,
70+
utils,
7071
};
7172

7273
#[cfg(unix)]

src/cli/self_update/unix.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ use tracing::{error, warn};
77
use super::install_bins;
88
use super::shell::{self, Posix, UnixShell};
99
use crate::process::Process;
10-
use crate::utils::{self, Notification};
10+
use crate::utils;
11+
use crate::notifications::Notification;
1112

1213
// If the user is trying to install with sudo, on some systems this will
1314
// result in writing root-owned files to the user's home directory, because

src/diskio/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ use std::{fmt::Debug, fs::OpenOptions};
6666
use anyhow::Result;
6767

6868
use crate::process::Process;
69-
use crate::utils::notifications::Notification;
69+
use crate::notifications::Notification;
7070
use threaded::PoolReference;
7171

7272
/// Carries the implementation specific data for complete file transfers into the executor.

src/diskio/threaded.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use sharded_slab::pool::{OwnedRef, OwnedRefMut};
1515
use tracing::debug;
1616

1717
use super::{CompletedIo, Executor, Item, perform};
18-
use crate::utils::notifications::Notification;
18+
use crate::notifications::Notification;
1919

2020
#[derive(Copy, Clone, Debug, Enum)]
2121
pub(crate) enum Bucket {

src/dist/component/package.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ use tracing::warn;
1515
use crate::diskio::{CompletedIo, Executor, FileBuffer, IO_CHUNK_SIZE, Item, Kind, get_executor};
1616
use crate::dist::component::components::*;
1717
use crate::dist::component::transaction::*;
18+
use crate::notifications::Notification;
1819
use crate::dist::temp;
1920
use crate::errors::*;
2021
use crate::process::Process;
21-
use crate::utils::{self, Notification};
22+
use crate::utils;
2223

2324
/// The current metadata revision used by rust-installer
2425
pub(crate) const INSTALLER_VERSION: &str = "3";

src/dist/download.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,7 @@ impl<'a> DownloadCfg<'a> {
209209

210210
fn file_hash(path: &Path, notify_handler: &dyn Fn(Notification<'_>)) -> Result<String> {
211211
let mut hasher = Sha256::new();
212-
let notification_converter = |notification: crate::utils::Notification<'_>| {
213-
notify_handler(notification.into());
214-
};
215-
let mut downloaded = utils::FileReaderWithProgress::new_file(path, &notification_converter)?;
212+
let mut downloaded = utils::FileReaderWithProgress::new_file(path, notify_handler)?;
216213
use std::io::Read;
217214
let mut buf = vec![0; 32768];
218215
while let Ok(n) = downloaded.read(&mut buf) {

src/dist/manifestation.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -265,18 +265,16 @@ impl Manifestation {
265265
component.target.as_ref(),
266266
));
267267

268-
let notification_converter = |notification: crate::utils::Notification<'_>| {
269-
(download_cfg.notify_handler)(notification.into());
270-
};
271-
272268
let cx = PackageContext {
273269
tmp_cx,
274-
notify_handler: Some(&notification_converter),
270+
notify_handler: Some(download_cfg.notify_handler),
275271
process: download_cfg.process,
276272
};
277273

278-
let reader =
279-
utils::FileReaderWithProgress::new_file(&installer_file, &notification_converter)?;
274+
let reader = utils::FileReaderWithProgress::new_file(
275+
&installer_file,
276+
download_cfg.notify_handler,
277+
)?;
280278
let package = match format {
281279
CompressionKind::GZip => &TarGzPackage::new(reader, &cx)? as &dyn Package,
282280
CompressionKind::XZ => &TarXzPackage::new(reader, &cx)?,
@@ -487,14 +485,10 @@ impl Manifestation {
487485
}
488486

489487
// Install all the components in the installer
490-
let notification_converter = |notification: crate::utils::Notification<'_>| {
491-
notify_handler(notification.into());
492-
};
493-
let reader =
494-
utils::FileReaderWithProgress::new_file(&installer_file, &notification_converter)?;
488+
let reader = utils::FileReaderWithProgress::new_file(&installer_file, notify_handler)?;
495489
let cx = PackageContext {
496490
tmp_cx,
497-
notify_handler: Some(&notification_converter),
491+
notify_handler: Some(notify_handler),
498492
process,
499493
};
500494

src/dist/temp.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ impl Context {
103103
// This is technically racey, but the probability of getting the same
104104
// random names at exactly the same time is... low.
105105
if !raw::path_exists(&temp_dir) {
106-
(self.notify_handler)(Notification::CreatingDirectory(&temp_dir));
106+
(self.notify_handler)(Notification::CreatingDirectory("temp", &temp_dir));
107107
fs::create_dir(&temp_dir)
108108
.with_context(|| CreatingError::Directory(PathBuf::from(&temp_dir)))?;
109109
return Ok(Dir {

0 commit comments

Comments
 (0)