Skip to content

Commit 3d77339

Browse files
committed
Inline dist::temp::Notification variants into top-level Notification
1 parent 59a33dc commit 3d77339

File tree

4 files changed

+38
-72
lines changed

4 files changed

+38
-72
lines changed

src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ impl<'a> Cfg<'a> {
295295
let tmp_cx = temp::Context::new(
296296
rustup_dir.join("tmp"),
297297
dist_root_server.as_str(),
298-
Box::new(move |n| (notify_clone)(n.into())),
298+
Box::new(move |n| (notify_clone)(n)),
299299
);
300300
let dist_root = dist_root_server + "/dist";
301301

src/dist/temp.rs

Lines changed: 3 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
use std::fmt::{self, Display};
2-
use std::fs;
3-
use std::io;
4-
use std::ops;
51
use std::path::{Path, PathBuf};
2+
use std::{fmt, fs, ops};
63

74
pub(crate) use anyhow::{Context as _, Result};
85
use thiserror::Error as ThisError;
96

10-
use crate::utils::{self, notify::NotificationLevel, raw};
7+
use crate::notifications::Notification;
8+
use crate::utils::{self, raw};
119

1210
#[derive(Debug, ThisError)]
1311
pub(crate) enum CreatingError {
@@ -68,56 +66,6 @@ impl Drop for File<'_> {
6866
}
6967
}
7068

71-
#[derive(Debug)]
72-
pub enum Notification<'a> {
73-
CreatingRoot(&'a Path),
74-
CreatingFile(&'a Path),
75-
CreatingDirectory(&'a Path),
76-
FileDeletion(&'a Path, io::Result<()>),
77-
DirectoryDeletion(&'a Path, io::Result<()>),
78-
}
79-
80-
impl Notification<'_> {
81-
pub(crate) fn level(&self) -> NotificationLevel {
82-
use self::Notification::*;
83-
match self {
84-
CreatingRoot(_) | CreatingFile(_) | CreatingDirectory(_) => NotificationLevel::Debug,
85-
FileDeletion(_, result) | DirectoryDeletion(_, result) => {
86-
if result.is_ok() {
87-
NotificationLevel::Debug
88-
} else {
89-
NotificationLevel::Warn
90-
}
91-
}
92-
}
93-
}
94-
}
95-
96-
impl Display for Notification<'_> {
97-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> std::result::Result<(), fmt::Error> {
98-
use self::Notification::*;
99-
match self {
100-
CreatingRoot(path) => write!(f, "creating temp root: {}", path.display()),
101-
CreatingFile(path) => write!(f, "creating temp file: {}", path.display()),
102-
CreatingDirectory(path) => write!(f, "creating temp directory: {}", path.display()),
103-
FileDeletion(path, result) => {
104-
if result.is_ok() {
105-
write!(f, "deleted temp file: {}", path.display())
106-
} else {
107-
write!(f, "could not delete temp file: {}", path.display())
108-
}
109-
}
110-
DirectoryDeletion(path, result) => {
111-
if result.is_ok() {
112-
write!(f, "deleted temp directory: {}", path.display())
113-
} else {
114-
write!(f, "could not delete temp directory: {}", path.display())
115-
}
116-
}
117-
}
118-
}
119-
}
120-
12169
pub struct Context {
12270
root_directory: PathBuf,
12371
pub dist_server: String,

src/notifications.rs

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
use std::fmt::{self, Display};
2+
use std::io;
23
use std::path::{Path, PathBuf};
34

45
use crate::settings::MetadataVersion;
5-
use crate::{
6-
dist::{ToolchainDesc, temp},
7-
toolchain::ToolchainName,
8-
utils::notify::NotificationLevel,
9-
};
6+
use crate::{dist::ToolchainDesc, toolchain::ToolchainName, utils::notify::NotificationLevel};
107

118
#[derive(Debug)]
12-
pub(crate) enum Notification<'a> {
9+
pub enum Notification<'a> {
1310
Install(crate::dist::Notification<'a>),
1411
Utils(crate::utils::Notification<'a>),
15-
Temp(temp::Notification<'a>),
16-
12+
CreatingRoot(&'a Path),
13+
CreatingFile(&'a Path),
14+
CreatingDirectory(&'a Path),
15+
FileDeletion(&'a Path, io::Result<()>),
16+
DirectoryDeletion(&'a Path, io::Result<()>),
1717
SetAutoInstall(&'a str),
1818
SetDefaultToolchain(Option<&'a ToolchainName>),
1919
SetOverrideToolchain(&'a Path, &'a str),
@@ -50,19 +50,21 @@ impl<'a> From<crate::utils::Notification<'a>> for Notification<'a> {
5050
Notification::Utils(n)
5151
}
5252
}
53-
impl<'a> From<temp::Notification<'a>> for Notification<'a> {
54-
fn from(n: temp::Notification<'a>) -> Self {
55-
Notification::Temp(n)
56-
}
57-
}
5853

5954
impl Notification<'_> {
6055
pub(crate) fn level(&self) -> NotificationLevel {
6156
use self::Notification::*;
6257
match self {
6358
Install(n) => n.level(),
6459
Utils(n) => n.level(),
65-
Temp(n) => n.level(),
60+
CreatingRoot(_) | CreatingFile(_) | CreatingDirectory(_) => NotificationLevel::Debug,
61+
FileDeletion(_, result) | DirectoryDeletion(_, result) => {
62+
if result.is_ok() {
63+
NotificationLevel::Debug
64+
} else {
65+
NotificationLevel::Warn
66+
}
67+
}
6668
ToolchainDirectory(_)
6769
| LookingForToolchain(_)
6870
| InstallingToolchain(_)
@@ -92,7 +94,23 @@ impl Display for Notification<'_> {
9294
match self {
9395
Install(n) => n.fmt(f),
9496
Utils(n) => n.fmt(f),
95-
Temp(n) => n.fmt(f),
97+
CreatingRoot(path) => write!(f, "creating temp root: {}", path.display()),
98+
CreatingFile(path) => write!(f, "creating temp file: {}", path.display()),
99+
CreatingDirectory(path) => write!(f, "creating temp directory: {}", path.display()),
100+
FileDeletion(path, result) => {
101+
if result.is_ok() {
102+
write!(f, "deleted temp file: {}", path.display())
103+
} else {
104+
write!(f, "could not delete temp file: {}", path.display())
105+
}
106+
}
107+
DirectoryDeletion(path, result) => {
108+
if result.is_ok() {
109+
write!(f, "deleted temp directory: {}", path.display())
110+
} else {
111+
write!(f, "could not delete temp directory: {}", path.display())
112+
}
113+
}
96114
SetAutoInstall(auto) => write!(f, "auto install set to '{auto}'"),
97115
SetDefaultToolchain(None) => write!(f, "default toolchain unset"),
98116
SetDefaultToolchain(Some(name)) => write!(f, "default toolchain set to '{name}'"),

src/settings.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ impl Settings {
147147
}
148148

149149
#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
150-
pub(crate) enum MetadataVersion {
150+
pub enum MetadataVersion {
151151
#[serde(rename = "2")]
152152
V2,
153153
#[serde(rename = "12")]

0 commit comments

Comments
 (0)