@@ -22,24 +22,29 @@ pub(crate) enum CreatingError {
22
22
}
23
23
24
24
#[ 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 ,
31
28
}
32
29
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
+ }
37
36
}
38
37
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
+ }
43
48
}
44
49
45
50
#[ derive( Debug ) ]
@@ -48,6 +53,32 @@ pub struct File<'a> {
48
53
path : PathBuf ,
49
54
}
50
55
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
+
51
82
impl < ' a > Notification < ' a > {
52
83
pub ( crate ) fn level ( & self ) -> NotificationLevel {
53
84
use self :: Notification :: * ;
@@ -89,6 +120,12 @@ impl<'a> Display for Notification<'a> {
89
120
}
90
121
}
91
122
123
+ pub struct Cfg {
124
+ root_directory : PathBuf ,
125
+ pub dist_server : String ,
126
+ notify_handler : Box < dyn Fn ( Notification < ' _ > ) > ,
127
+ }
128
+
92
129
impl Cfg {
93
130
pub fn new (
94
131
root_directory : PathBuf ,
@@ -170,40 +207,3 @@ impl fmt::Debug for Cfg {
170
207
. finish ( )
171
208
}
172
209
}
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