Skip to content

Commit c6cbab6

Browse files
djcrami3l
authored andcommitted
temp: keep definitions and impls together
1 parent 1196554 commit c6cbab6

File tree

1 file changed

+51
-51
lines changed

1 file changed

+51
-51
lines changed

src/dist/temp.rs

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,29 @@ pub(crate) enum CreatingError {
2222
}
2323

2424
#[derive(Debug)]
25-
pub enum Notification<'a> {
26-
CreatingRoot(&'a Path),
27-
CreatingFile(&'a Path),
28-
CreatingDirectory(&'a Path),
29-
FileDeletion(&'a Path, io::Result<()>),
30-
DirectoryDeletion(&'a Path, io::Result<()>),
25+
pub(crate) struct Dir<'a> {
26+
cfg: &'a Cfg,
27+
path: PathBuf,
3128
}
3229

33-
pub struct Cfg {
34-
root_directory: PathBuf,
35-
pub dist_server: String,
36-
notify_handler: Box<dyn Fn(Notification<'_>)>,
30+
impl<'a> ops::Deref for Dir<'a> {
31+
type Target = Path;
32+
33+
fn deref(&self) -> &Path {
34+
self.path.as_path()
35+
}
3736
}
3837

39-
#[derive(Debug)]
40-
pub(crate) struct Dir<'a> {
41-
cfg: &'a Cfg,
42-
path: PathBuf,
38+
impl<'a> Drop for Dir<'a> {
39+
fn drop(&mut self) {
40+
if raw::is_directory(&self.path) {
41+
let n = Notification::DirectoryDeletion(
42+
&self.path,
43+
remove_dir_all::remove_dir_all(&self.path),
44+
);
45+
(self.cfg.notify_handler)(n);
46+
}
47+
}
4348
}
4449

4550
#[derive(Debug)]
@@ -48,6 +53,32 @@ pub struct File<'a> {
4853
path: PathBuf,
4954
}
5055

56+
impl<'a> ops::Deref for File<'a> {
57+
type Target = Path;
58+
59+
fn deref(&self) -> &Path {
60+
self.path.as_path()
61+
}
62+
}
63+
64+
impl<'a> Drop for File<'a> {
65+
fn drop(&mut self) {
66+
if raw::is_file(&self.path) {
67+
let n = Notification::FileDeletion(&self.path, fs::remove_file(&self.path));
68+
(self.cfg.notify_handler)(n);
69+
}
70+
}
71+
}
72+
73+
#[derive(Debug)]
74+
pub enum Notification<'a> {
75+
CreatingRoot(&'a Path),
76+
CreatingFile(&'a Path),
77+
CreatingDirectory(&'a Path),
78+
FileDeletion(&'a Path, io::Result<()>),
79+
DirectoryDeletion(&'a Path, io::Result<()>),
80+
}
81+
5182
impl<'a> Notification<'a> {
5283
pub(crate) fn level(&self) -> NotificationLevel {
5384
use self::Notification::*;
@@ -89,6 +120,12 @@ impl<'a> Display for Notification<'a> {
89120
}
90121
}
91122

123+
pub struct Cfg {
124+
root_directory: PathBuf,
125+
pub dist_server: String,
126+
notify_handler: Box<dyn Fn(Notification<'_>)>,
127+
}
128+
92129
impl Cfg {
93130
pub fn new(
94131
root_directory: PathBuf,
@@ -170,40 +207,3 @@ impl fmt::Debug for Cfg {
170207
.finish()
171208
}
172209
}
173-
174-
impl<'a> ops::Deref for Dir<'a> {
175-
type Target = Path;
176-
177-
fn deref(&self) -> &Path {
178-
self.path.as_path()
179-
}
180-
}
181-
182-
impl<'a> ops::Deref for File<'a> {
183-
type Target = Path;
184-
185-
fn deref(&self) -> &Path {
186-
self.path.as_path()
187-
}
188-
}
189-
190-
impl<'a> Drop for Dir<'a> {
191-
fn drop(&mut self) {
192-
if raw::is_directory(&self.path) {
193-
let n = Notification::DirectoryDeletion(
194-
&self.path,
195-
remove_dir_all::remove_dir_all(&self.path),
196-
);
197-
(self.cfg.notify_handler)(n);
198-
}
199-
}
200-
}
201-
202-
impl<'a> Drop for File<'a> {
203-
fn drop(&mut self) {
204-
if raw::is_file(&self.path) {
205-
let n = Notification::FileDeletion(&self.path, fs::remove_file(&self.path));
206-
(self.cfg.notify_handler)(n);
207-
}
208-
}
209-
}

0 commit comments

Comments
 (0)